opencv利用攝像頭抓取視訊方法-ubuntu
阿新 • • 發佈:2019-01-17
#include "opencv/highgui.h" #include "opencv/cv.h" using namespace std; using namespace cv; int main(int argc, char** argv){ cvNamedWindow("testcamera", CV_WINDOW_AUTOSIZE); CvCapture* capture; if (argc == 1){ capture=cvCaptureFromCAM(0); printf("capture 0\n"); } else { capture = cvCreateFileCapture(argv[1]); printf("capture argv1\n"); } assert(capture != NULL); IplImage* frame; frame = cvCreateImage(cvSize(640, 320), IPL_DEPTH_16U, 3); while(1){ frame = cvQueryFrame(capture); if (!frame) break; cvShowImage("testcamera", frame); char c=cvWaitKey(33); if (c==27) break; } cvReleaseCapture(&capture); cvDestroyWindow("testcamera"); return 0; }