8

我在 Ubuntu 13.04(在 Acer C7 Chromebook 上)上使用 OpenCV 2.4.6,并且我正在使用一个简单的测试程序来查看我的网络摄像头是否可以与 OpenCV 一起使用。它适用于 Cheese 和 Skype,所以我知道网络摄像头本身不是问题。

这是我的代码(编译时没有任何错误):

#include "opencv2/opencv.hpp"
#include <stdio.h>
#include <stdlib.h>

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
  cv::VideoCapture cap;
  if(argc > 1)
    {
      cap.open(string(argv[1]));
    }
  else
    {
      cap.open(CV_CAP_ANY);
    }
  if(!cap.isOpened())
    {
      printf("Error: could not load a camera or video.\n");
    }
  Mat frame;
  namedWindow("video", 1);
  for(;;)
  {
    waitKey(20);
    cap >> frame;
  if(!frame.data)
    {
      printf("Error: no frame data.\n");
      break;
    }
    imshow("video", frame);
  }
}

如果我在没有任何参数的情况下运行程序(因为我希望它使用 CV_CAP_ANY),我会得到

Error: could not load a camera or video.
init done 
opengl support available 
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
Error: no frame data.

如果我指定 /dev/video0 (我唯一的相机)作为参数,我得到

demux_wavpack: (open_wv_file:127) open_wv_file: non-seekable inputs aren't supported yet.
(ERROR)icvOpenAVI_XINE(): Unable to open source '/dev/video0'
init done 
opengl support available 
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
libpng warning: Application built with libpng-1.2.49 but running with 1.5.12
GStreamer Plugin: Embedded video playback halted; module source reported: Could not read from resource.
Error: no frame data.

如果我指定视频文件的路径作为参数,它可以正常播放视频。

我会很感激任何帮助。提前致谢!

4

2 回答 2

3

Opencv 2.4.6 有一个错误,请看这里

此外试试这个: cv::VideoCapture cap = cv::VideoCapture(0);

希望它有所帮助!

于 2013-07-12T15:05:42.153 回答
0

您可以尝试将waitKey(20)值更改为 20 到 80。某些计算机的工作值是 20、30、40、50....

于 2013-09-29T13:53:47.167 回答