OpenCV计时器不能从另一个线程停止

发布于 2025-01-23 22:03:17 字数 2805 浏览 1 评论 0原文

在Linux ARM上运行时,我对OpenCV 2.4有问题。

我不使用代码中的计时器,但是当它获得错误计时器时,无法从另一个线程停止 我的代码

void displayImage(const unsigned char *pData, int width, int height)
{
    int channels = 1;
    IplImage* cv_image = cvCreateImageHeader(cvSize(width,height), IPL_DEPTH_8U, channels);
    if (!cv_image)
    {
        return;
    }
    cvSetData(cv_image, (void*)pData, cv_image->widthStep);
    cvNamedWindow("DisplayWindow", CV_WINDOW_AUTOSIZE);
    cvShowImage("DisplayWindow", cv_image);
    cvWaitKey(3);
    cvReleaseImageHeader(&cv_image);
}

void destroyDisplay()
{
    cvDestroyWindow("DisplayWindow");
    cvWaitKey(10);
}

呼叫者线程

unsigned int threadRun()
{
    int sleeptime = 0;
    while (!stop_)
    {
        sleeptime = 100;//milliseconds
        try
        {
            SharedDataPtr<ByteArray> responseData = stub_.invoke(METHOD_GET_EVENTS, NullRequest());
            if (stop_)
            {
                return 0;
            }
            
            if (!responseData.get())
            {
                return 0;
            }

            Response response;
            deserializeResponse(responseData, &response);

            if (response.Error())
            {
                Param param = response.getParam();
                if(param.msgCode == STATUS_FINISH)
                {
                    destroyDisplay();
                }
                sleeptime = 0;
            }

            if (response.hasStreamData())
            {
                unsigned int nWidth = response.getStreamData().get()->Width();
                unsigned int nHeight = response.getStreamData().get()->Height();
                displayImage(response.getStreamData().get(), nWidth, nHeight);
                sleeptime = 0;
            }
            if (sleeptime > 0){
                sleep(sleeptime);
            }
        }
        catch (...)
        {
        }
    }

main.cpp

int main()
{
    // start listening tcp port
    start_listing(threadRun,...);
    while(!exit)
    {
        // some other executions
    }
    
    return 0;
}

threadrun触发了TCP端口,它在从客户端发送的数据上读取和执行流程。

我只使用OpenCV的API。

此代码在窗口中正常工作,但是在Linux ARM中,它会出现错误qobject ::〜QObject计时器在代码到达MAIN的“返回0”线后,无法从另一个线程停止。看来有一个对象以前没有删除,但我找不到它。我添加了回溯,但信息不足以追踪

./ samplecode(_z11sig_handleri+0x20)[0x10080] /Lib/arm-linux-gnueabihf/libc.so.6(+0x25260).. /USR/lib/arm-linux-gnueabihf/libqt5core.so.5(_ZN15QSocketNotifier10SetEnableDeb +0x47) [0x76349274] /USR/LIB/ARM-LINUX-GNUEABIHF/LIBQT5CORE.SO.5(_ZN15QSOCKETCOCTNOTIFIERD1EV +0X15) [0x763492DA]

我发现,如果使用CVNamedWindow或CvShowiMage,则会创建一个计时对象。我试图在呼叫CvDestroywindow之后销毁此计时器,但似乎没有办法使用OpenCV来做到这一点。

我做错了什么吗?

I have a problem with opencv 2.4 when run on linux arm.

I don't use timer in my code but when it get error Timers cannot be stopped from another thread
My code

void displayImage(const unsigned char *pData, int width, int height)
{
    int channels = 1;
    IplImage* cv_image = cvCreateImageHeader(cvSize(width,height), IPL_DEPTH_8U, channels);
    if (!cv_image)
    {
        return;
    }
    cvSetData(cv_image, (void*)pData, cv_image->widthStep);
    cvNamedWindow("DisplayWindow", CV_WINDOW_AUTOSIZE);
    cvShowImage("DisplayWindow", cv_image);
    cvWaitKey(3);
    cvReleaseImageHeader(&cv_image);
}

void destroyDisplay()
{
    cvDestroyWindow("DisplayWindow");
    cvWaitKey(10);
}

caller thread

unsigned int threadRun()
{
    int sleeptime = 0;
    while (!stop_)
    {
        sleeptime = 100;//milliseconds
        try
        {
            SharedDataPtr<ByteArray> responseData = stub_.invoke(METHOD_GET_EVENTS, NullRequest());
            if (stop_)
            {
                return 0;
            }
            
            if (!responseData.get())
            {
                return 0;
            }

            Response response;
            deserializeResponse(responseData, &response);

            if (response.Error())
            {
                Param param = response.getParam();
                if(param.msgCode == STATUS_FINISH)
                {
                    destroyDisplay();
                }
                sleeptime = 0;
            }

            if (response.hasStreamData())
            {
                unsigned int nWidth = response.getStreamData().get()->Width();
                unsigned int nHeight = response.getStreamData().get()->Height();
                displayImage(response.getStreamData().get(), nWidth, nHeight);
                sleeptime = 0;
            }
            if (sleeptime > 0){
                sleep(sleeptime);
            }
        }
        catch (...)
        {
        }
    }

main.cpp

int main()
{
    // start listening tcp port
    start_listing(threadRun,...);
    while(!exit)
    {
        // some other executions
    }
    
    return 0;
}

threadRun trigger by a tcp port, it read and execute process base on data sent from client.

I only use api of opencv.

This code work fine in window, but in linux arm it get error QObject::~QObject Timers cannot be stopped from another thread after code reached line "return 0" of main. It seem that there is a object isn't delete before but I can't found it. I add backtrace but it is too insufficient information to trace

./samplecode(_Z11sig_handleri+0x20)[0x10080]
/lib/arm-linux-gnueabihf/libc.so.6(+0x25260)[0x76587260]
/usr/lib/arm-linux-gnueabihf/libQt5Core.so.5(_ZN15QSocketNotifier10setEnabledEb+0x47)[0x76349274]
/usr/lib/arm-linux-gnueabihf/libQt5Core.so.5(_ZN15QSocketNotifierD1Ev+0x15)[0x763492da]

I found that there is a Timer object is created if cvNamedWindow or cvShowImage is used. I try to destroy this Timer after call cvDestroyWindow but it seem that there are no way to do that using opencv.

Am I did something wrong and how can i close the Timers as well as all QObject I used

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文