If you don't know how to set OpenCV configuration on Visual Studio 2008, please read previous post. This post continue to follow Open CV study.
I try to open jpg image and avi videoclip in VC2008 console window, and I try also to connect webcam with console window.
At first, type like below. and build and run!
#include <cv.h>
#include <highgui.h>
int main()
{
IplImage* img =
cvLoadImage( "test.jpg" );
//"test.jpg" should be in where you are coding;
open a image file
cvNamedWindow( "window1", CV_WINDOW_AUTOSIZE ); //to create window
cvShowImage( "window1", img ); //poject image file in window made before
cvWaitKey(0);//wait until next keyboard input
cvReleaseImage(
&img ); //memory release
cvDestroyWindow(
"window1" ); //close window
return 0;
}
Result |
you did one of the three missions!
Second, type this below, and build and run!
#include <cv.h>
#include <highgui.h>
int main()
{
cvNamedWindow( "yadong", 0 ); //open
a new window, size is not determined
cvResizeWindow( "yadong", 200,200); //determine window size
cvMoveWindow( "yadong", 100,100); //place window,
CvCapture*
capture = cvCreateFileCapture( "test.avi"
); //open avi file and ready to capture.
IplImage* frame;
//this variable is for captured image.
char key;
while(1)
{
frame =
cvQueryFrame( capture );//captured image from video
is saved in this pointer for instance.
if( !frame ) break;
cvShowImage(
"yadong", frame ); //project image into window
key =
cvWaitKey(20); //wait 20ms for check keyboard input
if( key == 27 ) break;
//27 means 'ESC'
}
cvReleaseCapture(
&capture );
cvDestroyWindow(
"yadong" );
return 0;
}
Result |
Second mission completed!
Finally, Let's connect and project webcam video on the console window.
#include <cv.h>
#include <highgui.h>
int main()
{
IplImage *frame;
CvCapture
*pCamera;
int key;
pCamera =
cvCaptureFromCAM(0);
cvNamedWindow( "molka", CV_WINDOW_AUTOSIZE);
while(1)
{
frame =
cvQueryFrame( pCamera );
cvShowImage(
"molka", frame);
key =
cvWaitKey(30);
if( (char)key==27 ) break;
}
cvReleaseCapture(&pCamera);
cvDestroyWindow("molka");
return 0;
}
Result |
댓글 없음:
댓글 쓰기