Good morning community,
I am developing an OpenCV and Qt based app where I detect the genre of the person looking to a camera, and I fire a script if the detected gender is "Male" and another script if "Female".
To detect face and gender I use a caffe model and the OpenCV inference engine. To prevent the GUI from freezing, i decided to use a separate thread for camera frames processing but my poor experience in multithreading is giving me some problems. Reading some articles seems that the correct way to use QThreads is using moveToThread function.

This is the basic structure of my program:

GDWidget.h
Qt Code:
  1. ..code..
  2. private:
  3. Ui::GDWidget *ui;
  4. cv::VideoCapture m_capture;
  5.  
  6. cv::Mat m_currentFrame;
  7.  
  8. // for capture thread
  9. QMutex *m_dataLock;
  10. GDDetector *m_worker;
  11. QThread *m_thread;
  12.  
  13. QString m_maleUrl = "https://app.onsign.tv/play/u0mAM5ju0R9cP4R5wr6L?repeat=1";
  14. QString m_femaleUrl = "https://app.onsign.tv/play/Q0CoHhopjpr8l1IaxC7v?repeat=1";
  15. };
To copy to clipboard, switch view to plain text mode 

GDWidget.cpp
Qt Code:
  1. void GDWidget::openCamera()
  2. {
  3. int camIdx = 0;
  4. m_worker = new GDDetector(this, camID, m_dataLock);
  5. m_thread = new QThread;
  6. m_worker->moveToThread(m_thread);
  7. connect(m_worker, &GDDetector::frameCaptured, this, &GDWidget::updateFrame);
  8.  
  9. connect(m_thread, SIGNAL(started()), m_worker, SLOT(processFrame()));
  10. connect(m_worker, SIGNAL(finished()), m_thread, SLOT(quit()));
  11. connect(m_worker, SIGNAL(finished()), m_worker, SLOT(deleteLater()));
  12. connect(m_thread, SIGNAL(finished()), m_thread, SLOT(deleteLater()));
  13. thread->start();
  14. m_worker->start();
  15. }
To copy to clipboard, switch view to plain text mode 

In my processFrame() i have an infinite loop (that stops when I set to true a variable). My problem is that I would get the thread paused ( for 10 seconds ) when I detect the person gender.

Qt Code:
  1. void GDDetector::processFrame()
  2. {
  3. m_running = true;
  4. m_capture.open(m_cameraIdx);
  5. cv::Mat tmp_frame;
  6.  
  7. ..code ..
  8.  
  9. while(m_running)
  10. {
  11. m_capture >> tmp_frame;
  12. if (!tmp_frame.empty())
  13. {
  14. detectFace(tmp_frame);
  15.  
  16. m_dataLock->lock();
  17. cvtColor(tmp_frame, m_sourceFrame, cv::COLOR_BGR2RGB);
  18. m_dataLock->unlock();
  19.  
  20. emit frameCaptured(&m_sourceFrame);
  21. }
  22.  
  23. ///// I WOULD PAUSE THIS LOOP WHEN I GET A SPECIFIC RESULT FROM THE detectFace ROUTINE ///
  24. }
  25.  
  26. emit processFinished();
  27.  
  28. m_capture.release();
  29. m_running = false;
  30. }
To copy to clipboard, switch view to plain text mode 

I would have a help in pausing the infinite loop when i detect the gender. Also I would know how to move my code to QtConcurrent module but I don't know how.
Any help will be appreciated

Regards