Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QT + OPENCV Label Pixmap



  • Hello all again. I have a webcamera which gives in input and i used OpenCV to draw the frames and show in one label (Did the conversions and etc). I want to filter Blue colors from the webcam and display in another Label. However, pixmap overrides whenever i try to move. I use it in a slot to update every QTimer Count.
    Heres the code.

    onlinecam >> onlineframes;
            currframes = QString::number(currframe);
            cv::cvtColor(onlineframes, hsv, cv::COLOR_BGR2HSV);
            cv::inRange(hsv, cv::Scalar(110,50,50), cv::Scalar(130, 255, 255), mask);
            cv::bitwise_and(onlineframes, onlineframes ,res, mask);
            cv::cvtColor(res, blue_image, cv::COLOR_BGR2RGB);
            //ui->textEdit->append("Current Frame: " + currframes);
            cv::cvtColor(onlineframes,  onlineframes, cv::COLOR_BGR2RGB);
            
            // cv::resize(onlineframes,onlineframes,cv::Size(vheight,vwidth), 0, 0, cv::INTER_AREA);
            QImage imdisplay((uchar*)onlineframes.data, onlineframes.cols, onlineframes.rows, QImage::Format_RGB888);
            QImage filtered_image((uchar*)blue_image.data, blue_image.cols, blue_image.rows, QImage::Format_RGB888);
            ui->binary_display->setPixmap(QPixmap::fromImage(filtered_image));
            
            ui->image_display->setPixmap(QPixmap::fromImage(imdisplay));
    

    The resulting video looks like this.
    ac819eed-22ad-423f-992f-8a3d24af518f-image.png

    I stopped the video cam because I don't want to show my picture. and I have a blue pen and waved around the camera. However, the resulting filtered image just overrides the previous pixmap that is set. Any Idea how to solve it?



  • @Pl45m4 @mrdebug I have solved it by using setTo. Turns out it was an opencv issue



  • Sorry but it is not clear, maybe my english is not so fluent.
    Do you want to merge more images in one?



  • @Stevendragoes

    So the problem is, that you get the blue parts from your previous frame in your current and next frame?!
    Try to clear your cv::Mat onlineframes before setting new data to pixmap.

            // This might work or else try to fill with zeros if it doesnt work 
            onlineframes.release();
            
            // then populate cv::Mat with current frame data
            onlinecam >> onlineframes;
           
            currframes = QString::number(currframe);
            cv::cvtColor(onlineframes, hsv, cv::COLOR_BGR2HSV);
            cv::inRange(hsv, cv::Scalar(110,50,50), cv::Scalar(130, 255, 255), mask);
            cv::bitwise_and(onlineframes, onlineframes ,res, mask);
            cv::cvtColor(res, blue_image, cv::COLOR_BGR2RGB);
            //ui->textEdit->append("Current Frame: " + currframes);
            cv::cvtColor(onlineframes,  onlineframes, cv::COLOR_BGR2RGB);
            
            // cv::resize(onlineframes,onlineframes,cv::Size(vheight,vwidth), 0, 0, cv::INTER_AREA);
            QImage imdisplay((uchar*)onlineframes.data, onlineframes.cols, onlineframes.rows, QImage::Format_RGB888);
            QImage filtered_image((uchar*)blue_image.data, blue_image.cols, blue_image.rows, QImage::Format_RGB888);
            ui->binary_display->setPixmap(QPixmap::fromImage(filtered_image));
    


  • @Pl45m4 Hello, Yes i get the problem of the previous frame existing in my current frame. Maybe filling it with zeros will do the trick I am still trying to figure it out



  • @mrdebug No no. I have the problem of my previous frames exisiting in my current frame.
    Hence, I got these movement frames



  • @Pl45m4 @mrdebug I have solved it by using setTo. Turns out it was an opencv issue


Log in to reply