Nominate our 2022 Qt Champions!

Displaying multiple OpenCV VideoCapture objects in QT

  • Hey Guys, I'm capturing webcam streams from two raspberry pis and I'm trying to carry out some image processing on both streams. I have two Qlabels I'm trying to use to display the images from the pis. However, whilst one stream displays in real time, the other has a 4-5 second delay. The same result occurs if I try to display one stream on both Qlabel objects. Is this a threading issue? Can you guys please help out?

    VideoCapture capWebcam;
    VideoCapture EyeintheSky;
    Mat matEyeInTheSky;
    QImage qimgEyeInTheSky;
    Mat matOriginal;
    QImage qimgOriginal;
     MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)
  ""); //from MJPG STreamer image processing
       if (capWebcam.isOpened() == false) {
       if(EyeintheSky.isOpened() == false) {
    void MainWindow::processFrameAndUpdateGUI() {;;
    if(matOriginal.empty() == true) {
        qDebug() << "Empty Picture";
    else {
       //  start of visual processing
        // Output Tri Track images to screen
        // map QImage to QLabel
        QImage qimgOriginal((uchar*),matOriginal.cols,matOriginal.rows, matOriginal.step,QImage::Format_RGB888);
        // Output Eye in the Sky to screen
        // map QImage to QLabel
        cvtColor(matEyeInTheSky, matEyeInTheSky, COLOR_BGR2RGB);
        QImage qimgEyeInTheSky((uchar*), matEyeInTheSky.cols, matEyeInTheSky.rows, matEyeInTheSky.step, QImage::Format_RGB888);
        // Process IK code.

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Partly it will come from your conversions and processing and the size of the image. Depending on the size of the image, it will also have an impact on the speed.

  • @SGaist The image resolution is at 640 x 480. I've also tried streaming at 320 x 240 to test and the result is the same thing.

  • Hi
    Did you try to show vodeo capture only from the slow one? I think it might be usefull to test if the second camera slow only when image from both cameras is shown or it's always slow.

    Another suggection is to try to swap devices. It may be some kind of hardware problem.

    The last suggestion is to try to use QGraphicsView as soon as it might be just quicker than labels. However I don't think that the problem you described is in labels.