I am trying to do some computer video by reading the webcam stream in openCV. I’ve tried with both the internal webcam and an external usb webcam which both are working great with programs like camorama, streamer etc.
part of my code:
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include "pic_manipulation.hpp"
#include "colorDetector.h"
#include <time.h>
using namespace std;
int main ( int argc, char **argv ){
string file="../test.avi";
cv::VideoCapture capture(0);//les video
if(!capture.isOpened()){
cout <<"could not read file"<<endl;
return -1;
}
double rate=capture.get(CV_CAP_PROP_FPS);
bool stop(false);
cv::Mat frame;
cv::namedWindow("Extract frame");
int delay=1000/rate;
while(!stop){
if(!capture.read(frame))break;
cv::imshow("Extract frame", frame);
sleep(delay/1000);
if(cv::waitKey(delay)>=0){
cout<<"stop"<<endl;
stop=true;
capture.release();
}
cout<< "one loop finished"<<endl;
}
return 0;
}
When I compile and run the program I dont get any errors or warnings, it just returns at if(!capture.isOpened()) (Or if i skip the isOpened it returns at the next if(…)).
It reads video files with no problem at all. Anyone know if it is some bug with my install of opencv or if it is the linux webcam setting that’s causing the problem?
I am using linux mint and building the project with cmake/g++
I resolved the problem by installing openCV following this excellent guide: A Comprehensive Guide to Installing and Configuring OpenCV 2.4.2 on Ubuntu
I suspect that I didnt set the right configurations for building ffmpeg, v4l on a 64 bit platform as specified in the above guide. Anycase, it finally works!