简体   繁体   中英

Webcam not working in Ubuntu 12.04, works with cheese, not for OpenCV

I recently reinstalled Ubuntu - 12.04. I am using webcam to take video for a program in OpenCV. It doesn't work for my webcam, but the same piece of code works for my friend. My webcam works with Cheese. The piece of code I am using is:

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include <opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define heightBirdEyeView 1000
#define widthBirdEyeView 1000   //earlier was 300 300
#define _USE_MATH_DEFINES

//public class VideoCapture;
using namespace cv;         
using namespace std;

int main(int argc, char** argv)
{
VideoCapture cap(0); // open the default camera

if(!cap.isOpened())
{ // check if we succeeded
cout<<"cam not open"<<endl;
return -1;}

 cout<<"yay"<<endl;

Mat frame;
while(1)
{
cap >> frame; 

imshow("frame", frame);

if(waitKey(30) >= 27) 
break;
}

return 0;}

What could be wrong?

v4l2或v4l可能会丢失,请检查您的make输出。这应该是highgui问题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM