Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 962
Jragon Avatar asked Jul 12 '13 14:07

Jragon


1 Answers

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 !

like image 99
Poko Avatar answered Sep 22 '22 18:09

Poko