pcduino里,Qt无法打开摄像头(调用了opencv)


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);//鏄剧ず鍥惧儚


}

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值