天天看点

opencv2获取计算机摄像头并显示

成功运行

#include "opencv2/highgui/highgui.hpp"

#include <iostream>

#include <vector>

#include <stdio.h>

using namespace cv;

using namespace std; 

int main (int argc, const char * argv[])

{

    cvNamedWindow("ccav", 1);

    CvCapture *capture = cvCaptureFromCAM(0);

    if (!capture)

    {

        printf("get camera error!\n");

        exit(1);

    }

    IplImage *frame;

    int key = 0;

    while (1 > key)

    {

        frame = cvQueryFrame(capture);

        cvShowImage("ccav", frame);

        key = cvWaitKey(10);

    }

    cvReleaseCapture(&capture);

    cvDestroyWindow("ccav");

    return 0;

}

其实是opencv1的东东。

继续阅读