QT displays the binarized image processed by opencv to adapt to the size of the control
When writing qt to display processed pictures recently, I found that Qlabel in qt can only display three-channel pictures, and the pictures after opencv binarization are single-channel. After checking some web pages and debugging, the following code ran successfully. The picture adapts to the size of the control
Mat img ;
cvtColor(threshold,img,CV_GRAY2RGB); //threshold 是单通道图像(mat格式) ,把单通道转换为三通道
QImage image5((const uchar*)img.data,img.cols,img.rows,img.cols*img.channels(),QImage::Format_RGB888);//转换成QImage格式
ui->colorView->setScaledContents(true); //colorView是控件名称 改成自己的名称 使得图片适应控件大小显示
ui->colorView->setPixmap(QPixmap::fromImage(image5));//将图片显示在QLabel上 colorView是控件名称 改成自己的名称