Capture video from camera in Mac OS X

若如初见. 提交于 2019-12-03 04:03:07

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.

Andrey

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

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