2 Replies Latest reply on Oct 5, 2016 3:24 PM by jonathan_intel

    How to write the C++ coding in openCV to stream video from IP address?

    Yeong

      Hi everyone,

       

      I'm writing a C++ coding in openCV to stream video from IP address but it doesn't work. Please help.

      Thank you.

       

      #include <opencv/cv.h>  
      #include <opencv2/highgui/highgui.hpp>  
      #include <opencv2/imgproc/imgproc.hpp>  
      #include <iostream>  
      #include <stdio.h>  
      using namespace std;  
      using namespace cv;  
      int main()  
      {  
          Mat frame;  
          namedWindow("video", 1);  
          VideoCapture cap("http://192.168.8.102:8080/video.mjpg");  
          if(!cap.isOpened())  
          {  
              cout<<"Camera not found"<<endl;  
              getchar();  
              return -1;  
          }  
          while ( cap.isOpened() )  
          {  
              cap >> frame;  
              if(frame.empty()) break;  
              imshow("video", frame);  
              if(waitKey(30) >= 0) break;  
          }     
          return 0;  
      }  
      
      
      
      

       

       

       

       

       

      For line 12, I also tried:

       

      cv::VideoCapture cap("ws://192.168.8.102:8080.mjpg");

       

      VideoCapture cap("http://192.168.8.102:8080/video.mjpg");

       

      cv::VideoCapture capture("http://user:password@192.168.8.102:8080/mjpeg.cgi?user=USERNAME&password=PWD&channel=0&.mjpg");

       

       

       

      I confirmed the IP address and port number are correct because I can view the video using web browser.