OpenCV (IP) camera frames per second are slow after the initial burst

EDIT: Updating to OpenCV 2.4.2 and FFMPEG 0.11.1 seems to have solved all the errors and connectivity issues, but it still hasn't solved the slowdown of frame rates.

I use the default OpenCV package in Ubuntu 12.04, which I believe is 2.3.1. I connect to the Foscam FI8910W, which transmits MJPEG. I saw people say that the best way is to use opencv + libjpeg + curl, since it is faster than gstreamer solution . Nevertheless, I can sometimes (in 50% of cases) connect to the camera from OpenCV as it is created and receive a video stream. This stream starts at about 30 frames per second for about 1 second, but then slows down to 5-10 frames per second. The project I'm working on will require that 6 cameras preferably work at a speed of 15-30 frames per second (faster).

Here are my questions:

  • Is this a problem that is fixed in 2.4.2 and should I just upgrade?
  • If not, any ideas why I get a short burst and then slow down?
  • Better solution to still use curl + libjpeg?
  • I see a lot of people who say that the solutions were published, but there are very few actual links to the messages with the solutions. Having all the solutions (both curl and gstreamer) referenced in one place will be very convenient at http://opencv-users.1802565.n2.nabble.com/IP-camera-solution-td7345005.html .

Here is my code:

VideoCapture cap; cap.open("http://10.10.1.10/videostream.asf?user=test&pwd=1234&resolution=32"); Mat frame; cap >> frame; wr.open("test.avi", CV_FOURCC('P','I','M','1'), 29.92, frame.size(), true); if(!wr.isOpened()) { cout << "Video writer open failed" << endl; return(-1); } Mat dst = Mat::zeros(frame.rows + HEADER_HEIGHT, frame.cols, CV_8UC3); Mat roi(dst, Rect(0, HEADER_HEIGHT-1, frame.cols, frame.rows)); Mat head(dst, Rect(0,0,frame.cols, HEADER_HEIGHT)); Mat zhead = Mat::zeros(head.rows, head.cols, CV_8UC3); namedWindow("test", 1); time_t tnow; tm *tS; double t1 = (double)getTickCount(); double t2; for(int i = 0; i>-1 ; i++) // infinite loop { cap >> frame; if(!frame.data) break; tnow = time(0); tS = localtime(&tnow); frame.copyTo(roi); std::ostringstream L1, L2; L1 << tS->tm_year+1900 << " " << coutPrep << tS->tm_mon+1 << " "; L1 << coutPrep << tS->tm_mday << " "; L1 << coutPrep << tS->tm_hour; L1 << ":" << coutPrep << tS->tm_min << ":" << coutPrep << tS->tm_sec; actValueStr = L1.str(); zhead.copyTo(head); putText(dst, actValueStr, Point(0,HEADER_HEIGHT/2), fontFace, fontScale, Scalar(0,255,0), fontThickness, 8); L2 << "Frame: " << i; t2 = (double)getTickCount(); L2 << " " << (t2 - t1)/getTickFrequency()*1000. << " ms"; t1 = (double)getTickCount(); actValueStr = L2.str(); putText(dst, actValueStr, Point(0,HEADER_HEIGHT), fontFace, fontScale, Scalar(0,255,0), fontThickness, 8); imshow("test", dst); wr << dst; // write frame to file cout << "Frame: " << i << endl; if(waitKey(30) >= 0) break; } 

The following errors are listed for proper operation:

 Opening 10.10.1.10 Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later. Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later. [asf @ 0x701de0] max_analyze_duration reached [asf @ 0x701de0] Estimating duration from bitrate, this may be inaccurate [asf @ 0x701de0] ignoring invalid packet_obj_size (21084 656 21720 21740) [asf @ 0x701de0] freeing incomplete packet size 21720, new 21696 [asf @ 0x701de0] ff asf bad header 0 at:1029744 [asf @ 0x701de0] ff asf skip 678 (unknown stream) [asf @ 0x701de0] ff asf bad header 45 at:1030589 [asf @ 0x701de0] packet_obj_size invalid [asf @ 0x701de0] ff asf bad header 29 at:1049378 [asf @ 0x701de0] packet_obj_size invalid [asf @ 0x701de0] freeing incomplete packet size 21820, new 21684 [asf @ 0x701de0] freeing incomplete packet size 21684, new 21836 Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later. Using network protocols without global network initialization. Please use avformat_network_init(), this will become mandatory later. [asf @ 0x701de0] Estimating duration from bitrate, this may be inaccurate Successfully opened network camera [swscaler @ 0x8cf400] No accelerated colorspace conversion found from yuv422p to bgr24. Output #0, avi, to 'test.avi': Stream #0.0: Video: mpeg1video (hq), yuv420p, 640x480, q=2-31, 19660 kb/s, 90k tbn, 29.97 tbc [swscaler @ 0x9d25c0] No accelerated colorspace conversion found from yuv422p to bgr24. Frame: 0 [swscaler @ 0xa89f20] No accelerated colorspace conversion found from yuv422p to bgr24. Frame: 1 [swscaler @ 0x7f7840] No accelerated colorspace conversion found from yuv422p to bgr24. Frame: 2 [swscaler @ 0xb9e6c0] No accelerated colorspace conversion found from yuv422p to bgr24. Frame: 3 

Sometimes it freezes after the first Estimating duration from bitrate statement

+4
source share
2 answers

Have you tried to delete the code that is written to disk? I saw very similar performance issues with USB cameras when the disk buffer is full. High frame rate first, and then drops sharply.

If this is a problem, another option is to change your compression codec to something more compressed.

0
source

Fast initial FPS, which changes to slow FPS, suggests that the camera increases exposure time to compensate for a poorly lit subject. The camera analyzes the first few frames, and then adjusts the exposure time accordingly.

The actual FPS seems to be a combination of two things:

  • Hardware Limitations (determines the maximum FPS)
  • Required exposure time (determines the minimum FPS value)

The hardware may have the bandwidth required to transmit X FPS, but in poorly lit conditions, exposure time may be required that slows down the actual FPS. For example, if each frame should be set to 0.1 seconds, the voice FPS will be 10.

To verify this, measure the FPS with a camera aimed at a poorly lit subject and compare it with FPS with a camera directed at a well-lit subject. Be sure to exaggerate the lighting conditions and give the camera a few seconds to find the desired exposure.

0
source

All Articles