用两个窗口进行对比
#include "stdafx.h" #include <iostream> #include <opencv2/core/core.hpp> #include <opencv2/highgui/highgui.hpp> #include "cv.h" using namespace cv; using namespace std; int g_slider_position = 0, temp; CvCapture *g_captrue = NULL; void onTrackbarSlide(int pos) { cvSetCaptureProperty(g_captrue, CV_CAP_PROP_POS_FRAMES, pos); temp = g_slider_position; } int main(int argc, char **argv) { cvNamedWindow("sample-out", CV_WINDOW_AUTOSIZE); //创建输出处理后视频的窗口 cvNamedWindow("sample", CV_WINDOW_AUTOSIZE); //创建初始视频窗口 g_captrue = cvCreateFileCapture("sample.avi"); //Cvcapture结构体赋值 int frames = (int)cvGetCaptureProperty(g_captrue, CV_CAP_PROP_FRAME_COUNT); //获取视频总帧数 if (frames != 0)///若视频存在即帧数不为0则创建滚动条 { cvCreateTrackbar("Position", "sample", &g_slider_position, frames, onTrackbarSlide); } IplImage *frame;//创建图像指针 while (1) { frame = cvQueryFrame(g_captrue);//读取一帧 if (!frame)//读完退出 break; cvShowImage("sample", frame);//显示在sample窗口中 IplImage* out = cvCreateImage(cvGetSize(frame), IPL_DEPTH_8U, 3); //创建视频地址并为其开辟空间。 cvSmooth(frame, out, CV_GAUSSIAN, 3, 3);//对每一帧高斯模糊 cvShowImage("sample-out", out);//视频输出到sample-out窗口中 char c = cvWaitKey(30);//每一帧间隔30ms cvSetTrackbarPos("Position", "sample", temp++);//滚动条随动 if (c == 27) break; } cvReleaseCapture(&g_captrue);//释放指针 cvDestroyWindow("sample");//删除sample初始视频窗口 cvDestroyWindow("sample-out");//删除sample-out处理后的视频窗口 return 0; }