การติดต่อกับกล้องโดย OpenCV นั้นจะใช้ชุดคำสั่งจาก highgui ซึ่งมีตัวอย่างดังนี้
#includeusing namespace std;#include#include#define CAMERA_ID 0#define DISPLAY_WINDOW_NAME "captured image"int main( int argc, char **argv ){// create camera capture object.CvCapture *pCapture = NULL;pCapture = cvCreateCameraCapture( CAMERA_ID );if ( pCapture == NULL ){cout << "ERROR: Failed to open camera" << endl;return EXIT_FAILURE;}// create window for displaying captured image.cvNamedWindow( DISPLAY_WINDOW_NAME );// capture and display// until user hit any key of the keyboardIplImage *pImage = NULL;do{pImage = cvQueryFrame( pCapture );cvShowImage( DISPLAY_WINDOW_NAME, pImage );} while ( cvWaitKey( 1 ) == -1 );// before exiting the program,// destroy the display window and// release the cameara capture object.cvDestroyWindow( DISPLAY_WINDOW_NAME );cvReleaseCapture( &pCapture );return 0;}
0 comments:
แสดงความคิดเห็น