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.
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?
-
So the problem is, that you get the blue parts from your previous frame in your current and next frame?!
Try to clear yourcv::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));