我正在使用opencv 2.4.7,Windows 7和vc++ 2010从foscam IP摄像机流式传输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;
   }
    }

}

非常感谢您提前提供的帮助。

最佳答案

查看您的网址:

“IP:PORT / cgi-bin / CGIProxy.fcgi?cmd = snapPicture2&usr = X&pwd = Y&.mjpg”

snapPicture2看起来可疑,不是吗?

我很确定,您的opencv代码没有问题,
它更像是您选择的网址仅检索1帧

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

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

07-26 09:42