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