1. OS: Win7
IDE: VS2010
2. Include Directories: ....../OpenCV2.2/include
....../OpenCV2.2/include/opencv
Library Directories: ....../OpenCV2.2/lib
Additional Dependencies: opencv_core220d.lib, opencv_highgui220d.lib
3. Code:
#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
int g_slider_position = 0; // Slider position
CvCapture * g_capture = NULL; // AVI video capture
// Recall function: Set frame position in track bar
void onTrackbarSlide(int pos){
// Set CvCapture property (CV_CAP_PROP_POS_FRAMES/CV_CAP_PROP_POS_AVI_RATIO)
cvSetCaptureProperty(g_capture, CV_CAP_PROP_POS_FRAMES, pos);
}
int _tmain(int argc, _TCHAR* argv[])
{
// Track AVI window
cvNamedWindow("TrackAVI", CV_WINDOW_AUTOSIZE);
// Capture AVI file
g_capture = cvCreateFileCapture("AVI Video Path");
// Count frames of AVI video
int frames = (int) cvGetCaptureProperty(g_capture, CV_CAP_PROP_FRAME_COUNT);
if(frames != 0){
// Create track bar (Label, Window, Position, Frames Number, Recall Function)
cvCreateTrackbar("Position", "TrackAVI", &g_slider_position, frames, onTrackbarSlide);
}
// Frame as image
IplImage * frame;
while(1){
// Query next frame
frame = cvQueryFrame(g_capture);
if(!frame){
// Video Over
break;
}
// Show the current frame
cvShowImage("TrackAVI", frame);
// Wait 33 ms
char c = cvWaitKey(33);
if(c == 27){
// ESC Quit
break;
}
}
// Release CvCapture
cvReleaseCapture(&g_capture);
// Destory Window
cvDestroyWindow("TrackAVI");
return 0;
}