欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

程序员文章站 2022-07-05 10:14:24
...

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

AfxBeginThread函数

包含文件:#include<afxwin.h>

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

}

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