c++ 11多线程例子 opencv读入视频设置滚动条
2017-06-09 14:25
225 查看
#include <Windows.h> #include <iostream> #include<thread> #include<opencv2\opencv.hpp> using namespace cv; using namespace std; #define WINDOW_NAME "video" int g_frame = 1; int g_max_frame; bool flag = false; void on_Trackbar(int, void*) { flag = true; } int i = 0; void thread_fun1(Mat &img1,int& i) { cvtColor(img1, img1, CV_BGR2GRAY); i++; cout << "thread_1: " << i << endl; } void thread_fun2(Mat &img2,int& i) { cvtColor(img2, img2, CV_BGR2GRAY); i++; cout << "thread_2: " << i << endl; } int main() { thread thread_test[2]; Mat frame, img1, img2; VideoCapture cap("D:\\加油站车位检测\\gas_station_all_func_video_20161207_入口拥堵加入vibe_开始占用就输出占用\\gas_station_all_func_video\\ch03.mp4"); if (!cap.isOpened()) { cout << "no video1" << endl; } namedWindow(WINDOW_NAME, 1); g_max_frame = cap.get(CV_CAP_PROP_FRAME_COUNT);//////总共的视频帧 char TrackbarName[50]; sprintf(TrackbarName, "帧数%d", g_max_frame); createTrackbar(TrackbarName, WINDOW_NAME, &g_frame, g_max_frame, on_Trackbar);//////设置滑动条拖动的回调函数 int count = 0; while (1) { cout << "main: "<<i << endl; count++; cap >> frame; resize(frame, frame, Size(960, 600)); frame.copyTo(img1); frame.copyTo(img2); thread_test[0] = thread(&thread_fun1, ref(img1), ref(i)); thread_test[0].join(); imshow("img1", img1); thread_test[1] = thread(&thread_fun2, ref(img2), ref(i)); thread_test[1].join(); imshow("img2", img2); imshow("video", frame); cvWaitKey(10); if (flag) { cap.set(CV_CAP_PROP_POS_FRAMES, g_frame); flag = false; } } system("pause"); }
相关文章推荐
- 用opencv'打开avi视频并设置滚动条随之移动
- 【转】OpenCV的C++版本播放视频的综合例子
- 利用OpenCV读入一个彩色视频文件并以灰度格式输出
- opencv [c++版] 学习笔记(2) 在MFC基于对话框界面上播放视频
- Opencv第二个程序之-------带滚动条AVI视频播放
- Opencv中的Bug(实现读入一个彩色视频文件并以灰度格式输出这个视频文件,学习opencv例2-10)
- opencv 学习第二天 学习opencv(中文版)将一个视频读入后以灰度方式输出
- 为Dev-C++安装设置OpenCV
- OpenCV读入图片序列进行HOG行人检测并保存为视频
- opencv关于视频添加滚动条的问题 一样的程序 为什么结构不一样呢!奇怪极了(4)
- MFC对话框和opencv的结合 读入视频
- 用OpenCV读取视频的简单例子
- OPENCV(1)图片,视频读入,输出(highgui)
- OpenCV播放视频 加随视频播放自动滚动的滚动条
- opencv关于视频添加滚动条的问题 一样的程序 为什么结构不一样呢!奇怪极了(4)
- opencv录制与播放视频设置
- opencv [c++版] 学习笔记(1) 显示图像及播放视频
- OpenCV播放视频 加上滚动条
- OpenCV读入视频,灰度化,并Canny边缘检测
- Linux下OpenCV中cvCreateFileCapture读入视频失败的解决