| | |
| | | #define SOCKET_ERROR -1 |
| | | #endif /* _WIN32 */ |
| | | |
| | | #include <cstdio> |
| | | #include <vector> |
| | | #include <iostream> |
| | | using std::cerr; |
| | |
| | | int timeout; // master sock timeout, shutdown after timeout millis. |
| | | int quality; // jpeg compression [1..100] |
| | | |
| | | int _write(int sock, char *s, int len) |
| | | int _write(int sock, char const*const s, int len) |
| | | { |
| | | if (len < 1) { len = strlen(s); } |
| | | return ::send(sock, s, len, 0); |
| | |
| | | params.push_back(IMWRITE_JPEG_QUALITY); |
| | | params.push_back(quality); |
| | | cv::imencode(".jpg", frame, outbuf, params); |
| | | unsigned int outlen = outbuf.size(); |
| | | size_t outlen = outbuf.size(); |
| | | |
| | | #ifdef _WIN32 |
| | | for (unsigned i = 0; i<rread.fd_count; i++) |
| | |
| | | else // existing client, just stream pix |
| | | { |
| | | char head[400]; |
| | | sprintf(head, "--mjpegstream\r\nContent-Type: image/jpeg\r\nContent-Length: %lu\r\n\r\n", outlen); |
| | | sprintf(head, "--mjpegstream\r\nContent-Type: image/jpeg\r\nContent-Length: %zu\r\n\r\n", outlen); |
| | | _write(s, head, 0); |
| | | int n = _write(s, (char*)(&outbuf[0]), outlen); |
| | | //cerr << "known client " << s << " " << n << endl; |
| | |
| | | std::cout << " MJPEG-stream sent. \n"; |
| | | } |
| | | |
| | | |
| | | CvCapture* get_capture_webcam(int index) { |
| | | CvCapture* cap = NULL; |
| | | try { |
| | | cap = (CvCapture*)new cv::VideoCapture(index); |
| | | //((cv::VideoCapture*)cap)->set(CV_CAP_PROP_FRAME_WIDTH, 1280); |
| | | //((cv::VideoCapture*)cap)->set(CV_CAP_PROP_FRAME_HEIGHT, 960); |
| | | } |
| | | catch (...) { |
| | | std::cout << " Error: Web-camera " << index << " can't be opened! \n"; |
| | | } |
| | | return cap; |
| | | } |
| | | |
| | | IplImage* get_webcam_frame(CvCapture *cap) { |
| | | IplImage* src = NULL; |
| | | try { |
| | | cv::VideoCapture &cpp_cap = *(cv::VideoCapture *)cap; |
| | | cv::Mat frame; |
| | | if (cpp_cap.isOpened()) { |
| | | cpp_cap >> frame; |
| | | src = cvCreateImage(cvSize(frame.cols, frame.rows), 8, frame.channels()); |
| | | *src = frame; |
| | | } |
| | | } |
| | | catch (...) { |
| | | std::cout << " Web-camera stoped! \n"; |
| | | } |
| | | return src; |
| | | } |
| | | |
| | | |
| | | #endif // OPENCV |