zoukankan      html  css  js  c++  java
  • opencv做的简单播放器


      1 #include <opencv2/highgui/highgui.hpp>
      2 #include <opencv2/imgproc/imgproc.hpp>
      3 #include <string>
      4 #include <iostream>
      5 #include <fstream>
      6 
      7 using namespace std;
      8 
      9 int g_slider_position = 0;
     10 int g_run = 1, g_dontset = 0;
     11 cv::VideoCapture g_cap;
     12 void onTrackbarSlide(int pos, void*) {
     13 	g_cap.set(cv::CAP_PROP_POS_FRAMES, pos);
     14 
     15 	if (!g_dontset)
     16 		g_run = 1;
     17 	g_dontset = 0;
     18 }
     19 int main(int argc, char** argv) {
     20 	std::string s = "Video/2020-06/e0927594e320877035894dc0a435f1b6.mp4";
     21 
     22 	g_cap.open(s);//视频读取结构,通过传入字符串
     23 
     24 	int frames = (int)g_cap.get(cv::CAP_PROP_FRAME_COUNT);
     25 	int tmpw = (int)g_cap.get(cv::CAP_PROP_FRAME_WIDTH);
     26 	int tmph = (int)g_cap.get(cv::CAP_PROP_FRAME_HEIGHT);
     27 
     28 	cout << "Video has" << frames << "frames of dimensions(" << tmpw << "," << tmph << ")." << endl;
     29 
     30 	cv::createTrackbar("Position", "Example2_4", &g_slider_position, frames, onTrackbarSlide);
     31 
     32 	cv::Mat frame;
     33 	for (;;) {
     34 		if (g_run != 0) {
     35 			g_cap >> frame; if (frame.empty())break;
     36 			int current_pos = (int)g_cap.get(cv::CAP_PROP_POS_FRAMES);
     37 			g_dontset = 1;
     38 
     39 			cv::setTrackbarPos("Position", "Example2_4", current_pos);
     40 			cv::imshow("Example2_4", frame);
     41 
     42 			g_run -= 1;
     43 		}
     44 
     45 		char c = (char)cv::waitKey(10);
     46 		if (c == 's') {
     47 			g_run = 1;  cout << "Singal step, run = " << g_run << endl;
     48 		}
     49 		if (c == 'r') {
     50 			g_run = -1; cout << "Run mode, run = " << g_run << endl;
     51 		}
     52 		if (c == 27)
     53 			break;
     54 
     55 	}
     56 	cv::destroyWindow("Example2_4");
     57 	return 0;
     58 }
    追求吾之所爱
  • 相关阅读:
    hdu 2553 N皇后问题(dfs)
    hdu 1043 Eight(双向bfs)
    牛人的ACM经验 (转)
    康托和逆康托展开(转)
    hiho Mission Impossible 6(模拟 未提交验证。。)
    数组越界也可以这么巧~~~
    poj 1679 The Unique MST(次小生成树)
    zoj 3204 Connect them(最小生成树)
    hdu 4463 Outlets(最小生成树)
    廖雪峰Java1-2程序基础-8字符和字符串
  • 原文地址:https://www.cnblogs.com/rstz/p/14391016.html
Copyright © 2011-2022 走看看