OpenCV网络(IP)摄像头在初始突发后每秒帧率变慢

4

编辑:升级到OpenCV 2.4.2和FFMPEG 0.11.1似乎解决了所有错误和连接问题,但是仍然没有解决帧率下降的问题。

我在Ubuntu 12.04中使用默认的OpenCV软件包,我相信它是2.3.1版本。我连接到一个流MJPEG的Foscam FI8910W。我看到有人说最好的方法是使用opencv+libjpeg+curl,因为这比gstreamer解决方案更快。然而,我偶尔(50%的时间)可以从构建的OpenCV中连到相机并得到视频流。该视频流开始时约为30 fps,大约持续1秒钟,然后就会变慢到5-10 fps。我正在开发的项目需要有6个相机,最好以每秒15-30帧运行(速度越快越好)。

以下是我的问题:

  1. 这是否是在2.4.2中修复的问题,我应该升级?
  2. 如果不是,为什么我会得到短暂的突发然后变慢?
  3. 最佳解决方案仍然是使用curl+libjpeg吗?
  4. 我看到很多人说已经发布了解决方案,但是实际的解决方案链接很少。将所有实际解决方案(包括curl和gstreamer)引用在一个地方会非常方便,例如http://opencv-users.1802565.n2.nabble.com/IP-camera-solution-td7345005.html

以下是我的代码:

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

以下是程序正常运行时列出的错误信息:
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

有时在第一次“从比特率估计持续时间”语句之后出现挂起的情况。

你确定不是相机问题吗?能否试着将相机对准强光并检查帧速率? - Sunius
你解决了这个问题吗?想要选择一个答案吗? - Jake
2个回答

0

快速的初始FPS变为慢速的FPS,可能表明相机正在增加曝光时间以补偿光线不足的主体。相机会分析前几帧,然后相应地调整曝光时间。

实际FPS似乎是两个因素的组合:

  1. 硬件限制(定义最大FPS)
  2. 所需曝光时间(定义最小FPS)

硬件可能具有传输X FPS所需的带宽,但光线不足的条件可能需要减慢实际FPS的曝光时间。例如,如果每帧需要曝光0.1秒,则最快的FPS将为10。

要进行测试,请将相机对准光线不足的主体并测量FPS,然后将其与对准光线充足的主体时的FPS进行比较。一定要夸大照明条件,并给相机几秒钟来检测所需的曝光。


0

您尝试过移除写入磁盘的代码吗?我曾经在USB摄像头中见过非常类似的性能问题,当磁盘缓冲区满了时,帧率一开始很高,然后急剧下降。

如果这是问题,另一个选项是将压缩编解码器更改为更显著地进行压缩。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接