【发布时间】:2012-02-20 16:04:30
【问题描述】:
我需要调用 cvQueryFrame(使用 opencv 从网络摄像头捕获帧)而不是使用 boost 创建的线程。这是一个小示例代码:
void testCVfunc(){
IplImage* frame;
CvCapture *capture;
capture = cvCreateCameraCapture(CV_CAP_ANY);
if(!capture){
exit(1);
}
frame = cvQueryFrame(capture);
cvNamedWindow("testCV", 1);
while(frame = cvQueryFrame(capture)){
if(!frame){
exit(2);
}
cvShowImage("testCV", frame);
cvWaitKey(1);
}
cvReleaseImage(&frame);
cvReleaseCapture(&capture);
}
int main(){
//Method 1: without boost::thread, works fine
testCVfunc();
//Method 2: with boost::thread, show black screen
char entree;
boost::thread threadTestCV = boost::thread(&testCVfunc);
std::cin >> entree;
}
正如 cmets 所说,如果我不从 boost::thread 调用它,testCVfunc 就可以完成它的工作,但是如果我使用 boost::thread,则会出现黑屏。
我不明白这个问题,也许有人明白?
感谢您的帮助。
【问题讨论】:
标签: c++ multithreading boost opencv