- 视频播放时点击窗口关闭按钮(即小叉号)关闭窗口
- 隐藏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");
}