OpenCV VideoCapture can't read from my webcam at all

I'm using OpenCV 2.4.6 on Ubuntu 13.04 (on an Acer C7 Chromebook), and I'm using a simple test program to see if my webcam will work with OpenCV. It works fine with Cheese and Skype, so I know that the webcam itself isn't the issue.

Here is my code (which compiles without any errors):

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

If I run the program without any arguments (since I want it to use CV_CAP_ANY), I get

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.

If I specify /dev/video0 (my only camera) as the argument, I get

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.

If I specify the path to a video file as the argument, it plays the video just fine.

I'd appreciate any help. Thanks in advance!


There is a bug on Opencv 2.4.6 please take a look here

moreover try this: cv::VideoCapture cap = cv::VideoCapture(0);

Hope it helped !


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

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

上一篇: Google自定义搜索API按图片网址搜索图片

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