ip camera foscam jpeg在opencv中流式传输,只从视频中读取第一帧

时间:2014-01-09 21:01:54

标签: opencv camera streaming ip mjpeg

我正在使用opencv 2.4.7,Windows 7和vc ++ 2010从foscam ip camera流式传输mjpeg。 cap.isOpened不为null,但仅显示第一帧,并在第二轮中从循环中断。这是我正在使用的代码的一部分:

VideoCapture cap("http://IP:PORT/cgi-bin/CGIProxy.fcgi?cmd=snapPicture2&usr=X&pwd=Y&.mjpg"); // open the video file for reading

if ( !cap.isOpened() )  // if not success, exit program
{
     std::cout << "Cannot open the video file" << std::endl;
     return -1;
}

cap.set(CV_CAP_PROP_POS_MSEC, 30); //start the video at 300ms

double fps = cap.get(CV_CAP_PROP_FPS); //get the frames per seconds of the video

 std::cout << "Frame per seconds : " << fps << std::endl;

namedWindow("MyVideo",CV_WINDOW_AUTOSIZE); //create a window called "MyVideo"
int cnt=0;
 Mat frame;


for(;;)
{

    bool bSuccess = cap.read(frame); // read a new frame from video

    if (!bSuccess) //if not success, break loop
    {
                    std::cout << "Cannot read the frame from video file" << std::endl;

                  break;
    }

    imshow("MyVideo", frame); //show the frame in "MyVideo" window

    if(waitKey(33) == 27) //wait for 'esc' key press for 30 ms. If 'esc' key is pressed, break loop
   {
            std::cout << "esc key is pressed by user" << std::endl; 
            break; 
   }
    }

}

我提前感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

看看你的网址:

“IP:PORT /的cgi-bin / CGIProxy.fcgi CMD = snapPicture2&安培; USR = X&安培; PWD = Y&安培; .mjpg”

snapPicture2 看起来很可疑,不是吗?

我很确定,你的opencv代码没问题, 它更像你选择的网址只检索1帧

请查阅您的手册以获取正确的网址

http://www.ispyconnect.com/man.aspx?n=foscam