Multithreading 来自线程的cvQueryFrame
我正在尝试使用opencv(3.1.0)从单独线程中的windows网络摄像头接收帧。见下面的例子。它在cvQueryFrame(TestThread)上阻塞,无法返回任何内容。没有错误。。。感谢您的帮助。谢谢Multithreading 来自线程的cvQueryFrame,multithreading,opencv,Multithreading,Opencv,我正在尝试使用opencv(3.1.0)从单独线程中的windows网络摄像头接收帧。见下面的例子。它在cvQueryFrame(TestThread)上阻塞,无法返回任何内容。没有错误。。。感谢您的帮助。谢谢 #包括 #包括“opencv2/highgui/highgui.hpp” #包括 #包括 void TestThread(void*param); int main(int argc,字符**argv) { 捕获*捕获; 把手; 捕获=cvCaptureFromCAM(0);
#包括
#包括“opencv2/highgui/highgui.hpp”
#包括
#包括
void TestThread(void*param);
int main(int argc,字符**argv)
{
捕获*捕获;
把手;
捕获=cvCaptureFromCAM(0);
如果(!捕获){
std::如果将捕获
初始化也移动到线程中会怎么样?它可能不喜欢在一个线程中创建对象并在另一个线程中使用。是的,如果我在线程中初始化CvCapture,那么它可以查询帧。谢谢)
#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();
}