c++ 11多线程例子 opencv读入视频设置滚动条

#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");
}