我想使用多线程来处理视频中捕获的每个帧,所以首先,我尝试了一个简单的测试:在两个线程中显示相同的视频,但问题是子线程可以' t显示视频。它只是可以显示主线程的视频。任何人都可以帮我解决这个问题吗?这是我的代码:
HANDLE hMutex = CreateMutex(NULL, false, "IMG");
int main()
{
videoMultiThread();
return 0;
}
DWORD WINAPI TL_FRAME(LPVOID lpParamter)
{
WaitForSingleObject(hMutex,INFINITE);
IplImage* frame=(IplImage*)lpParamter;
cvShowImage("TL",frame);
cvWaitKey(5);
cout<<"Thread captured"<<endl;
ReleaseMutex(hMutex);
return 0;
}
void videoMultiThread()
{
CvCapture * cap=cvCreateFileCapture("VIDEO.avi");
IplImage * frame;
while(1)
{
WaitForSingleObject(hMutex,INFINITE);
frame=cvQueryFrame(cap);
if(!frame)break;
cvShowImage( "frame",frame);
cout<<"main thread captured"<<endl;
//MultiThread
HANDLE hThread = CreateThread(NULL,0,TL_FRAME,frame,0,NULL);
CloseHandle(hThread);
char c=waitKey(5);
if (c==27)break;
ReleaseMutex(hMutex);
}
cvReleaseCapture(&cap);
cvDestroyAllWindows();
}