OpenCV Timers cannot be stopped from another thread

403 Views Asked by At

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

0

There are 0 best solutions below