Multithreading for OpenCV Functions with Qt Signal Slot
C++ multithreading with QT and event-based computer vision architecture
1 min readJan 1, 2021
Developing OpenCV based vision applications with QT open up possibilities of different powerful features such as QT Signals & Slots [1] and Qthread [2].
In the given example [ link ], you will see
- Qthread for worker class. The main steps are listed here
1-Create your QObjects,
2-connect your signals,
3-create your QThread,
4-move your QObjects to the QThread and
5-start the thread.
- Signal & Slot for cv::Mat structure. The signal/slot mechanisms will ensure that thread boundary is crossed properly and safely. Important to note! Register the type cv::Mat via
Q_DECLARE_METATYP
at the beginning of the constructor. Exact syntax is qRegisterMetaType<cv::Mat>(“cv::Mat”);
The console output and opencv imshow in my case is
Main thread id = 0x298
pipeline is opened
camera stream available!
Worker thread id = 0x3ad8
References: