//2-3使用滚动条控制视频文件播放位置
#include "stdafx.h"
#include "highgui.h"
int g_slider_position=0;
CvCapture* g_capture=NULL;
void onTrackbarSlide(int pos){
cvSetCaptureProperty(
g_capture,
CV_CAP_PROP_POS_FRAMES,
pos
);
}
int main( int argc, char** argv )
{
cvNamedWindow("exp2-3",CV_WINDOW_AUTOSIZE);
CvCapture* g_capture=cvCreateFileCapture("D:\\VCcodes\\00OpenCv\\图像与视频\\video.long.mjpg.avi");
// CvCapture* capture=cvCreateFileCapture("video.avi");
int frames=(int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
if(frames!=0){
cvCreateTrackbar("position","exp2-3",&g_slider_position,frames,onTrackbarSlide);
}
IplImage* frame;
while(1)
{
frame=cvQueryFrame(g_capture);
if(!frame) break;
cvShowImage("exp2-3",frame);
char c = cvWaitKey(33);
if(c==27) break;
}
cvReleaseCapture(&g_capture);
cvDestroyWindow("exp2-3");
}
#include "stdafx.h"
#include "highgui.h"
int g_slider_position=0;
CvCapture* g_capture=NULL;
void onTrackbarSlide(int pos){
cvSetCaptureProperty(
g_capture,
CV_CAP_PROP_POS_FRAMES,
pos
);
}
int main( int argc, char** argv )
{
cvNamedWindow("exp2-3",CV_WINDOW_AUTOSIZE);
CvCapture* g_capture=cvCreateFileCapture("D:\\VCcodes\\00OpenCv\\图像与视频\\video.long.mjpg.avi");
// CvCapture* capture=cvCreateFileCapture("video.avi");
int frames=(int)cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
if(frames!=0){
cvCreateTrackbar("position","exp2-3",&g_slider_position,frames,onTrackbarSlide);
}
IplImage* frame;
while(1)
{
frame=cvQueryFrame(g_capture);
if(!frame) break;
cvShowImage("exp2-3",frame);
char c = cvWaitKey(33);
if(c==27) break;
}
cvReleaseCapture(&g_capture);
cvDestroyWindow("exp2-3");
}