我正在尝试使用opencv(3.1.0)从单独线程中的Windows上的网络摄像头接收帧。见下面的例子。它停留在cvQueryFrame(TestThread)并且无法返回任何内容。没有错误...感谢任何帮助。谢谢!
#include <iostream>
#include "opencv2/highgui/highgui.hpp"
#include <process.h>
#include <windows.h>
void TestThread(void *param);
int main(int argc, char** argv)
{
CvCapture* capture;
HANDLE handle;
capture = cvCaptureFromCAM(0);
if (!capture) {
std::cout << "capture error";
return -1;
}
IplImage* frame = cvQueryFrame( capture );
std::cout << "main: " << frame->width;
handle = (HANDLE) _beginthread( TestThread, 0, capture);
WaitForSingleObject(handle,INFINITE);
std::cout << "done";
cvReleaseCapture(&capture);
return 0;
}
void TestThread(void *param)
{
CvCapture* capture=(CvCapture*)param;
IplImage* frame = cvQueryFrame( capture );
std::cout << "thread: " << frame->width;
_endthread();
}