0

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.

user3170824
  • 1
  • 1
  • 1

1 Answers1

1

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

berak
  • 39,159
  • 9
  • 91
  • 89
  • hey sorry, no idea. but i'm pretty sure, your current url only retrieves one single snapshot, not a stream. maybe it's a limitation of that camera ? read the small print. maybe it can't deliver a stream at all ? – berak Jan 09 '14 at 22:19
  • oh thanks actually you were right. the url was incorrect camera model was FI9821W not 9821W sorry for my mistake. I am working on the new url. – user3170824 Jan 09 '14 at 22:37
  • best of luck from here ;) – berak Jan 09 '14 at 22:48