OpenCV2.3調用攝像頭程序,獲取圖片逐幀顯示:
- #include "highgui.h"
-
- int main()
- {
- CvCapture* pCap = cvCreateCameraCapture( 1 );//這裡-1也可以,不過我的電腦裝的有CyberLink YouCam軟件,
- //OpenCV會默認調用該攝像頭,而不調用系統的驅動
- IplImage *frame = NULL;
-
- if (cvCreateCameraCapture == NULL)
- {
- return(0);
- }
-
- cvNamedWindow("Camera",CV_WINDOW_FULLSCREEN);
-
- while ((frame = cvQueryFrame(pCap)) != 0 && cvWaitKey(20) != 27)
- {
- frame = cvQueryFrame(pCap);
- cvShowImage("Camera", frame);
- }
-
- cvReleaseCapture(&pCap);
- cvDestroyWindow("Camera");
- return (0);
- }