cvCaptureFromCAM(0)、cvCaptureFromCAM(-1)、cvCreateCameraCapture(0)、cvCreateCameraCapture(-1)、都试过了,都无法打开摄像头,但是cvCaptureFromAVI()可以打开视频。用guvcview可以打开摄像头。 请问 该怎么办?
#include <QtCore/QCoreApplication>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <cv.h>
#include <highgui.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#include <time.h>
#include <ctype.h>
#include <sys/time.h>
#include <signal.h>
using namespace cv;
const char *cascade_name = "/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml";//鑴搁儴璇嗗埆
//static CvHaarClassifierCascade *cascade = 0;
static CvHaarClassifierCascade *cascade = 0;
static CvMemStorage *storage = 0;
void detect_and_draw(IplImage *image);
int main(int argc, char *argv[])
{
CvCapture *capture = 0;
IplImage* newImg;
IplImage *img;
storage = cvCreateMemStorage(0);
cascade = (CvHaarClassifierCascade*)cvLoad(cascade_name, 0, 0, 0);
namedWindow("result",WINDOW_AUTOSIZE);
//capture = cvCaptureFromAVI("capture.avi");
capture = cvCreateCameraCapture(6);
//capture = cvCaptureFromCAM(0);
//sleep(200);
while(1)
{
newImg = cvQueryFrame(capture);
//if(!newImg)
// break;
//img = cvCreateImage(cvSize(newImg->width/2, newImg->height/2), newImg->depth,newImg->nChannels);
//cvResize(newImg,img);
//缈昏浆鍥惧儚
//cvFlip(img,img,1);
//璋冪敤璇嗗埆鍜岀粯鍒跺浘鍍忕殑鍑芥暟
//detect_and_draw(img);
cvShowImage("result", newImg);
char c = waitKey(33);
if( 27 == c )
return 0;
}
cvReleaseCapture(&capture);//閲婃斁鎽勫儚澶?
cvDestroyWindow("result");//閿€姣佺獥鍙?}
void detect_and_draw(IplImage *image){
//startTime = getCurrentTime();
cvClearMemStorage(storage);
int scale = 1;
int i;
CvPoint ptcenter;
if(cascade){
CvSeq *faces = cvHaarDetectObjects(image, cascade, storage, 1.1, 2, CV_HAAR_DO_CANNY_PRUNING,
cvSize(80, 80));
for(i = 0; i<(faces ? faces->total : 0); i++){
CvRect *r = (CvRect*)cvGetSeqElem(faces, i);
ptcenter.x = (r->x + (r->width/2))*scale;
ptcenter.y = (r->y + (r->height/2))*scale;
cvCircle(image, ptcenter, (r->width + r->height)/4, CV_RGB(255,0,0), 3, 8, 0 );
}
}
cvShowImage("result",image);//鏄剧ず鍥惧儚
}