multithreading - Display Opencv image send by event to Qt GUI -
i trying days find proper solution following problem(stated below), , have no more ideas now. therefore, need more experienced devs:
i have class independant qt (and want stay this) generate opencv images in secundary thread. raise event pass 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 hooked mainwindow , method supposed display images on gui.
void mainwindow::displayframe(vector<mat>* frames) { vector<mat>* frames2 = new vector<mat>(); frames2 = frames; (int = 0; < frames2->size(); ++i) { this->camframes->at(i)->showimage(frames2->at(i)); } } during runtime, when main thread access images following error :
assert failure in qcoreapplication::sendevent: "cannot send events objects owned different thread.
i understand not using threads properly, have no idea how create asynchronous event now.
thank help, valentin
edit 1 :
it seems me real question : can use normal std::thread , native event communicate main qthread ?
here solution solve problem, after all.
the idea give main thread access mat coming second thread. modified function displayframe :
void mainwindow::displayframe(vector<mat>* frames) { //qthread:: qthread* this_thread = qthread::currentthread(); framewrapper* worker = new framewrapper(); worker->movetothread(this_thread); qobject::connect(worker, signal(framesent(vector<mat>*)), this, slot(showimg(vector<mat>*))); emit worker->framesent(frames); //this->camframes->at(0)->showimage(frame); } the new function showimg doing job of old displayframe. signal/slot process permit access image gui thread wanted.
Comments
Post a Comment