sivagnanamn
2018-03-21 013031ce3f80cd3297937ae126baecf4ea63d9e8
src/http_stream.cpp
@@ -37,6 +37,7 @@
#define SOCKET_ERROR   -1
#endif /* _WIN32 */
#include <cstdio>
#include <vector>
#include <iostream>
using std::cerr;
@@ -56,7 +57,7 @@
   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);
@@ -128,7 +129,7 @@
      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++)
@@ -169,7 +170,7 @@
         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;
@@ -194,4 +195,36 @@
   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