Capture video from camera in Mac OS X

前端 未结 2 854
悲&欢浪女
悲&欢浪女 2021-02-06 16:48

How I can filter video stream from camera in MacOS X. I write quicktime sequence grabber channel component, but it`s work only if app used SG API. If app used QTKit Capture the

相关标签:
2条回答
  • 2021-02-06 17:36

    It looks like there should be cvReleaseCapture(&capture); at the end.

    0 讨论(0)
  • 2021-02-06 17:49

    You could use OpenCV for video processing, it's a cross platform image/video processing library: http://opencv.willowgarage.com

    Your code would look something like this:

    CvCapture* capture = NULL;
    if ((capture = cvCaptureFromCAM(-1)) == NULL)
    {
        std::cerr << "!!! ERROR: vCaptureFromCAM No camera found\n";
        return -1;
    }
    
    cvNamedWindow("webcam", CV_WINDOW_AUTOSIZE);
    cvMoveWindow("webcam", 50, 50);
    
    cvQueryFrame(capture);
    
    IplImage* src = NULL;
    for (;;)
    {
        if ((src = cvQueryFrame(capture)) == NULL)
        {
                std::cerr << "!!! ERROR: vQueryFrame\n";
            break;
        }
    
        // perform processing on src->imageData 
    
        cvShowImage("webcam", &src);
    
        char key_pressed = cvWaitKey(2);
    
        if (key_pressed == 27) 
           break;
    }
    
    cvReleaseCapture(&camera);
    

    I had success using OpenCV on Mac OS X using cvCaptureFromCAM(0) instead of passing it -1. On linux, -1 seems to do Ok.

    0 讨论(0)
提交回复
热议问题