• 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");
    }
    
    
  • 相关阅读:
    LintCode "Binary Tree Serialization"
    LeetCode "Find the Duplicate Number"
    LintCode "Route Between Two Nodes in Graph"
    LintCode "Search a 2D Matrix II"
    LintCode "Submatrix Sum"
    LintCode "Sort Letters by Case"
    LeetCode "Peeking Iterator"
    LintCode "Sort Colors II"
    LeetCode "Move Zeroes"
    LintCode "Update Bits"
  • 原文地址:https://www.cnblogs.com/ggzone/p/10121348.html
Copyright © 2020-2023  润新知