Capture video from camera in Mac OS X

一个人想着一个人 提交于 2019-12-03 14:12:49

问题


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 component is not worked.

Somebody know how I can implement it?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3231497/capture-video-from-camera-in-mac-os-x

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!