使用cvQueryFrame和boost ::线程在一起 [英] Using cvQueryFrame and boost::thread together

查看:122
本文介绍了使用cvQueryFrame和boost ::线程在一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要调用 cvQueryFrame (捕获从OpenCV的摄像头帧),而不是用升压创建的线程。这里是一个小例子code:

I need to call cvQueryFrame (to capture a frame from a webcam with opencv) instead a thread created with boost. Here is a little example code:

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

随着评论说, testCVfunc 它的工作,如果我不从的boost ::线程中调用它,但我得到一个黑色的屏幕,如果我使用的boost ::线程
我不明白的问题,也许有人呢?

As the comments say, testCVfunc does its job if I don't call it from a boost::thread, but I get a black screen if I use boost::thread. I don't get the problem, maybe someone does?

感谢您的帮助。

推荐答案

我见过当从辅助线程执行OpenCV的一些问题,就很难查明问题的根源时的行为是不是在所有一致平台。

I've seen some problems when OpenCV is being executed from a secondary thread and it's difficult to pinpoint the origin of the problem when the behavior is not consistent on all platforms.

例如,源$ C ​​$ C完全符合OpenCV的2.3.0工作在Mac OS X 10.7.2 。我不知道你用的是什么平台,但事实上,它的工作在我的电脑上显示,OpenCV的与你所使用的平台的一些执行问题。

For instance, your source code worked perfectly with OpenCV 2.3.0 on Mac OS X 10.7.2. I don't know what platform you are using, but the fact that it worked on my computer indicates that OpenCV has some implementation issues with the platform you are using.

现在,如果你不能移动的OpenCV的code到主线程,那么你可能要开始考虑建立第二个程序来处理所有的OpenCV相关的任务,并使用某种IPC机制允许这程序与主应用程序进行通信。

Now, if you can't move OpenCV's code to the primary thread, then you might want to start thinking about creating a 2nd program to handle all OpenCV related tasks, and use some sort of IPC mechanism to allow this program to communicate with your main application.

这篇关于使用cvQueryFrame和boost ::线程在一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆