OpenCV:初试牛刀-带滚动条的视频播放-2

  • 视频播放时点击窗口关闭按钮(即小叉号)关闭窗口
  • 隐藏console控制台
  • 使用VideoCapture和createTrackbar实现滚动条控制视频播放
#include<iostream>
#include<Windows.h>

#include<opencv2/highgui/highgui.hpp>
#include<opencv2/core/core.hpp>
using namespace cv;
using namespace std;
#pragma comment( linker, "/subsystem:\"windows\" /entry:\"mainCRTStartup\"" )//隐藏console控制台


int curFrame = 0;
cv::VideoCapture v1;

void onTrackbarSlide(int pos,void*)
{
	v1.set(CV_CAP_PROP_POS_FRAMES, pos);
}


int main()
{
	namedWindow("Demo2", CV_WINDOW_AUTOSIZE | CV_WINDOW_FREERATIO);
	v1.open("H:/斯卡布罗集市.avi");
	if (!v1.isOpened())
	{
		cout << "Could not open " <<endl;
		return -1;
	}
	
	Mat frame;
	int frames = v1.get(CV_CAP_PROP_FRAME_COUNT);
	createTrackbar("position:", "Demo2", &curFrame, frames, onTrackbarSlide);
	while (1)
	{
		HWND hWnd = (HWND)cvGetWindowHandle("Demo2");
		v1 >> frame;
		if (frame.empty()||hWnd==NULL)break;//视频播放时点击窗口关闭按钮(即小叉号)关闭窗口
		imshow("Demo2", frame);
		
		if(waitKey(30)>0)break;
	}
	v1.release();
	destroyWindow("Demo2");
}


你可能感兴趣的:(滚动条,opencv,视频播放,opencv2,叉号关闭窗口)