0

我正在尝试了解 OpenCV 并在 youtube 上找到了一个非常好的教程,但是,每次我被告知在 Visual Studio 上“选择视频设备”时,都会弹出一个 R6010 错误,我必须继续中止程序。这是源代码。我正在使用 OpenCV 2.2, 2010 Visua Studio,有问题的相机是 HP TrueVision HD。谢谢!

//tracker1

#include<opencv\cvaux.h>
#include<opencv\highgui.h>
#include<opencv\cxcore.h>

#include<stdio.h>
#include<stdlib.h>

int main(int argc, char* []){

    CvSize size640x480 = cvSize(640, 480);

    CvCapture* p_capWebCam; //assign a webcam (later)

    IplImage* p_imgOriginal; //image given by the webcam
    IplImage* p_imgProcessed; //webcam image processed

    CvMemStorage* p_strStorage; //passing stored variables

    CvSeq* p_seqCircles;

    float* p_fltXYRadius; //3 points, 0 = X, 1 = Y, 2 = Radius

    int i; //looping integer

    char charCheckForEscKey;

    p_capWebCam = cvCaptureFromCAM(0);

    if(p_capWebCam == NULL){
        printf("error, webcam not found");
        getchar();
        return(-1);
    }

    cvNamedWindow("original", CV_WINDOW_AUTOSIZE);
    cvNamedWindow("processed", CV_WINDOW_AUTOSIZE);

    p_imgProcessed = cvCreateImage(size640x480, IPL_DEPTH_8U, 1);

    while(1){
        p_imgOriginal = cvQueryFrame(p_capWebCam); //get frame of webcame
        if(p_capWebCam == NULL){ //when the frame is not attained
            printf("error, no frames were attained");
            getchar();
            break;
        }

        cvInRangeS(p_imgOriginal, CV_RGB(175,0,0), CV_RGB(256, 100, 100), p_imgProcessed);

        p_strStorage = cvCreateMemStorage(0);

        cvSmooth(p_imgProcessed, p_imgProcessed, CV_GAUSSIAN, 9 ,9);

        p_seqCircles = cvHoughCircles(p_imgProcessed, p_strStorage, CV_HOUGH_GRADIENT, 2, p_imgProcessed->height/4, 100, 50, 10, 400);

        for(i=0; i<p_seqCircles->total; i++){
            p_fltXYRadius = (float*)cvGetSeqElem(p_seqCircles, i);
            printf("ball position x = %f, y = %f, r = %f \n", p_fltXYRadius[0], p_fltXYRadius[1], p_fltXYRadius[2]);

            cvCircle(p_imgOriginal, cvPoint(cvRound(p_fltXYRadius[0]), cvRound(p_fltXYRadius[1])), 3, CV_RGB(0, 255, 0), CV_FILLED);

            cvCircle(p_imgOriginal, cvPoint(cvRound(p_fltXYRadius[0]), cvRound(p_fltXYRadius[1])), cvRound(p_fltXYRadius[2]), CV_RGB(255, 0, 0), 3);
        }

        cvShowImage("original", p_imgOriginal);
        cvShowImage("processed", p_imgProcessed);

        cvReleaseMemStorage(&p_strStorage);

        charCheckForEscKey = cvWaitKey(10);
        if(charCheckForEscKey == 27) break;
    }

    cvReleaseCapture(&p_capWebCam);
    cvDestroyWindow("original");
    cvDestroyWindow("processed");


}
4

0 回答 0