user3170824
user3170824

Reputation: 1

ip camera foscam jpeg streaming in opencv, only reads first frame from video

I am using opencv 2.4.7, windows 7 and vc++2010 to stream mjpeg from a foscam ip camera. cap.isOpened is not null but only the first frame is displayed and breaks from loop in the second round. this is part of the code I am using:

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; 
   }
    }

}

I appreciate any help in advance.

Upvotes: 0

Views: 2618

Answers (1)

berak
berak

Reputation: 39796

look at your url:

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

snapPicture2 looks suspicious, no ?

i'm pretty sure, there's no problem with your opencv code, it's more like the url you choose only retrieves 1 frame

please lookup your manual for the correct stream url

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

Upvotes: 1

Related Questions