c++ - OpenCV imshow in Boost Threads -
below code tracking module. detector launched , when detects object of interest, creates tracker object track object using camshift on number of frames until detector finds object. code seems work fine when comment out imshow , waitkey in tracker. when call functions, following error when new tracker (apart first one) created:
qmetamethod::invoke: unable invoke methods return values in queued connections qobject::starttimer: qtimer can used threads started qthread i don't know if happening within boost or opencv. ideas how can fix problem? there better way go showing user position of object of interest? lot!
main:
#define face_detect_rate 10 tracker *currenttracker; boost::mutex displayedimagemutex; mat imagetoshow; // image displayed main thread void updatedisplayedimage(mat image){ if (displayedimagemutex.try_lock()){ image.copyto(imagetoshow); displayedimagemutex.unlock() } } rect detectorcallback(rect facerect){ // detector object returns face found here // tracker supposed track face in next set of frames tracker tracker(facerect); tracker.start(&updatedisplayedimage); currenttracker = &tracker; currenttracker->join(); } int main(int argc, char **argv){ videocapture capture(0); currenttracker = null; int framecount = 0; while (true){ mat frame; capture >> frame; if (framecount % face_detect_rate == 0){ detector detector; detector.start(frame, &detectorcallback); } if (displayedimagemutex.try_lock()){ if (imagetoshow.data){ imshow("results", imagetoshow); waitkey(1); } displayedimagemutex.unlock(); } } } tracker:
class tracker{ private: boost::thread *trackerthread; void run(void (*imageupdatefunc)(mat)){ while (true){ try{ ... //do camshift , stuff //show results //imshow("stream", imagewithface); //waitkey(10); imageupdatefunc(imagewithface); ... boost::this_thread::interruption_point(); } catch (const boost::thread::interrupted&){ break; } } } public: tracker(rect facerect){ ... } void start(void (*imageupdatefunc)(mat)){ trackerthread = new boost::thread(&tracker::run, this, imageupdatefunc); } void stop(){ trackerthread->interrupt(); } void join(){ trackerthread->join(); } };
Comments
Post a Comment