Opencv學習:多線程打開攝像頭

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

}

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章