OpenCV VideoCapture根本无法从我的网络摄像头读取

我在Ubuntu 13.04上使用OpenCV 2.4.6(在Acer C7 Chromebook上),我正在使用一个简单的测试程序来查看我的摄像头是否可以与OpenCV一起使用。 它适用于奶酪和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.

如果我将视频文件的路径指定为参数,则播放视频就好了。

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


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

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

希望它有帮助!


您可以尝试将waitKey(20)值更改为20,直到80.某台计算机的值为20,30,40,50 ....

链接地址: http://www.djcxy.com/p/14653.html

上一篇: OpenCV VideoCapture can't read from my webcam at all

下一篇: python: why does os.makedirs cause WindowsError?