学习OPENCV的第一个例子
#include <highgui.h>
#include <cassert>
#include <iostream>
#include <Windows.h>
using namespace std;
void OnTrackbarSlide(int pos);
int g_slider_position = 0;
CvCapture *g_capture = NULL;
int main(int argc , char ** argv)
{
assert(argc == 2);
cvNamedWindow("Example2",CV_WINDOW_AUTOSIZE);
g_capture = cvCreateFileCapture(argv[1]);
assert(g_capture != NULL);
int frames = (int) cvGetCaptureProperty(g_capture,CV_CAP_PROP_FRAME_COUNT);
int fps = (int) cvGetCaptureProperty(g_capture,CV_CAP_PROP_FPS);
const int step_time = 1000 / fps ;
if(frames != 0){
cvCreateTrackbar("Position","Example2",&g_slider_position,frames,OnTrackbarSlide);
}
IplImage *frame ;
while(1){
frame = cvQueryFrame(g_capture);
if(frame == NULL)
break;
cvShowImage("Example2",frame);
if(++g_slider_position % fps == 0)
cvSetTrackbarPos("Position","Example2",++g_slider_position);
char c = cvWaitKey(step_time);
if(c == 27)
break;
}
cvReleaseCapture(&g_capture);
cvDestroyWindow("Example2");
}
void OnTrackbarSlide(int pos)
{
cvSetCaptureProperty(g_capture,CV_CAP_PROP_POS_FRAMES,
pos);
}
OnTrackbarSlide(int pos)为滑块的回调函数.
别的函数可以忘文生义
运行之前请安装好opencv库,再在依赖库中设置好比如我用的opencv 2.1
cvcore210d.lib cv210d.lib highgui210d.lib