opencv 播放进度读取

来源:互联网 发布:网络挂号,厦门中医院 编辑:程序博客网 时间:2024/06/05 06:51
#include <iostream>#include <io.h>#include <opencv2/opencv.hpp>#include <Windows.h>using namespace std;#pragma comment(linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"") double g_pos = 0.0;CvCapture* pCapture = NULL;void coutInt( double pos ){char format[20];sprintf( format,"pos :%f\n",pos );OutputDebugString( format );}void track_change( int pos ){cvSetCaptureProperty( pCapture,CV_CAP_PROP_POS_AVI_RATIO,(double)pos / 100 );//g_pos = cvGetCaptureProperty( pCapture,CV_CAP_PROP_POS_AVI_RATIO );//cvSetCaptureProperty( pCapture,CV_CAP_PROP_POS_AVI_RATIO,1 );//g_pos = pos;}void main(){char in_file[] = "out.avi";char title[] = "Play Video";char track[] = "track control";pCapture = cvCreateFileCapture( in_file );if( pCapture == NULL ) return;cvNamedWindow( title,CV_WINDOW_AUTOSIZE );int init = 0;cvCreateTrackbar( track,title,&init,100,track_change );g_pos = cvGetCaptureProperty( pCapture,CV_CAP_PROP_POS_AVI_RATIO );int fps = cvGetCaptureProperty( pCapture,CV_CAP_PROP_FPS );if( fps == 0 ) return;int vfps = 1000 / fps;IplImage* pSrcImg = cvQueryFrame( pCapture );if( pSrcImg == NULL ) return;IplImage* pFrame = NULL;while( 1 ){pFrame = cvQueryFrame( pCapture );if( pFrame == NULL ) break;g_pos = cvGetCaptureProperty( pCapture,CV_CAP_PROP_POS_AVI_RATIO );//cvSetTrackbarPos( track, title,g_pos * 100 );coutInt( g_pos );cvShowImage( title,pFrame );cvWaitKey( vfps );}cvReleaseCapture( &pCapture );cvDestroyWindow( title );system("pause");return;}

原创粉丝点击