Opencv学习:多线程打开摄像头

Opencv学习笔记: C++ 多线程同时打开一个视频,或同时打开多个摄像头

AfxBeginThread函数

包含文件:#include

UINT read_video(LPVOID lpparam)
{
	VideoCapture capture;
	capture.open("C:/Users/x110276/Desktop/7.dav");
	printf("thread1!!!\n");
	if(!capture.isOpened())
	{
		printf("video open failed!\n");
		return  -1;
	}
	namedWindow("video",0);
	cv::resizeWindow("video",640,480);
	cv::Mat frame;
	while(1)
	{
		capture>>frame;
		if(frame.empty())
			break;
		imshow("video",frame);
		cv::waitKey(1);
	}
	capture.release();

	return 0;
}
UINT read_video2(LPVOID lpparam)
{
	VideoCapture capture;
	capture.open("C:/Users/x110276/Desktop/7.dav");
	printf("thread2!!!\n");
	if(!capture.isOpened())
	{
		printf("video open failed!\n");
		return  -1;
	}
	namedWindow("video2",0);
	cv::resizeWindow("video2",640,480);
	cv::Mat frame;
	while(1)
	{
		capture>>frame;
		if(frame.empty())
			break;
		imshow("video2",frame);
		cv::waitKey(1);
	}
	capture.release();

	return 0;
}
int _tmain(int argc, _TCHAR* argv[])
{
	CWinThread *pthread1, *pthread2;
	pthread1 =  AfxBeginThread(read_video,NULL);
	pthread2 =  AfxBeginThread(read_video2,NULL);
	system("pause");

}

 

你可能感兴趣的:(机器视觉,海康相机SDK)