mercredi 26 juillet 2017

Display Opencv image send by event to Qt GUI

I am trying for days to find a proper solution to the following problem, and I have no more ideas now, than asking to more experienced devs :

I have a class independant from QT (and I want it to stay like this) that generate openCV images in a secundary thread. Then it raise an event which pass the images.

    while (1)
        {
            if (timerActived & this->_camReady)
            {
                vector<Mat>* images = new vector<Mat>;
                images = this->AcquireImg();
                __raise this->frameAcquired(images);
            }
            this_thread::sleep_for(chrono::milliseconds(_frameTimeLaps));
        }

This event is hooked by my MainWindow and a method is supposed to display my images on my GUI.

    void MainWindow::displayFrame(vector<Mat>* frames) {
        vector<Mat>* frames2 = new vector<Mat>();
        frames2 = frames;
        for (int i = 0; i < frames2->size(); ++i) {
            this->camFrames->at(i)->showImage(frames2->at(i));
        }
    }

During the runTime, when the Main Thread access the images I get the following error :

ASSERT failure in QCoreApplication::sendEvent: "Cannot send events to objects owned by a different thread.

I understand that I am not using threads properly, but I have no idea how to create an asynchron event now.

Thank you for help, Valentin

Aucun commentaire:

Enregistrer un commentaire