제4 장 방과 후 문제 4

       -》    -》   -》  -》            lib  :
 opencv_imgproc220d.lib opencv_legacy220d.lib opencv_ml220d.lib opencv_core220d.lib opencv_highgui220d.lib opencv_video220d.lib 
// 4-4.cpp :              。
//

#include "stdafx.h"
#include<opencv/cv.h>
#include<opencv/highgui.h>

/*int g_switch_value = 1;
void switch_off_function() {printf("Pause
");}; //YOU COULD DO SOMETHING WITH THESE FUNCTIONS TOO void switch_on_function() {printf("Run
");}; void switch_callback( int position ) { if( position == 0 ) { switch_off_function(); } else { switch_on_function(); } } int main() { IplImage *frame; CvCapture* g_capture = NULL; if(!(g_capture = cvCreateFileCapture("C:\\test.avi"))) { printf("Failed to open %s
","C:\\test.avi"); return -1; } cvNamedWindow( "SliderControl", 1 ); cvCreateTrackbar( "Switch", "SliderControl", &g_switch_value, 1, switch_callback ); while( 1 ) { if(g_switch_value) { frame = cvQueryFrame( g_capture ); if( !frame ) break; } cvShowImage( "SliderControl", frame); if(cvWaitKey(10)==27 ) break; } cvReleaseCapture( &g_capture ); cvDestroyWindow( "SliderControl" ); return(0); }*/ int g_switch_value = 1; int g_slider_position = 0; CvCapture* g_capture = NULL; void onTrackbarSlide(int pos) { cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES,pos); } void switch_callback( int position ) { if( position == 0 ) { printf("Pause
"); } else { printf("on
"); } } int main() { cvNamedWindow("Test Vedio Slide",CV_WINDOW_AUTOSIZE); g_capture = cvCreateFileCapture("C:\\test.avi"); int frames = (int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT); int frameRate = (int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FPS); if(frames!=0) { cvCreateTrackbar( "Switch","Test Vedio Slide",&g_switch_value,1,switch_callback); cvCreateTrackbar("position","Test Vedio Slide", &g_slider_position, frames, onTrackbarSlide); } IplImage* frame; while(g_slider_position<frames) { if(g_switch_value==1) { frame = cvQueryFrame(g_capture); if(!frame) break; cvShowImage("Test Vedio Slide", frame); char c = cvWaitKey(frameRate); cvSetTrackbarPos("position","Test Vedio Slide", g_slider_position); onTrackbarSlide(g_slider_position); if(c == 27) break; g_slider_position++; } else { if(cvWaitKey(10)==27 ) break; } } cvReleaseCapture(&g_capture); cvDestroyWindow("Test Vedio Slide"); }

좋은 웹페이지 즐겨찾기