0. 写在前面
用于记录一下,在Qt上显示Mat的数据,记录代码如下;文章来源地址https://www.toymoban.com/news/detail-844630.html
//QLabel中显示处理结果
void MainWindow::matToLabelShow(QLabel *label, Mat &mat)
{
cv::Mat Rgb;
QImage Img;
if (mat.channels() == 3)//RGB Img
{
cv::cvtColor(mat, Rgb,COLOR_BGR2RGB);
Img = QImage((const uchar*)(Rgb.data), Rgb.cols, Rgb.rows, Rgb.cols * Rgb.channels(), QImage::Format_RGB888);
}
else//Gray Img
{
Img = QImage((const uchar*)(mat.data), mat.cols, mat.rows, mat.cols * mat.channels(), QImage::Format_Indexed8);
}
//自适应显示
int ori_width = Img.size().width();
int ori_height = Img.size().height();
int m_width = label->size().width();
int m_height = label->size().height();
int pro;
if(ori_width/m_width >= ori_height / m_height)
{
pro = ori_width / m_width;
}
else
{
pro = ori_height / m_height;
}
int scale_width = ori_width / pro;
int scale_height = ori_height / pro;
QImage *scale_image = new QImage();
*scale_image = Img.scaled(scale_width,scale_height,Qt::KeepAspectRatio);
//label->setScaledContents(true);//充满整个屏幕
label->setAlignment(Qt::AlignCenter);
label->setPixmap(QPixmap::fromImage(*scale_image));
}
文章来源:https://www.toymoban.com/news/detail-844630.html
到了这里,关于Qt-在QLabel上显示Mat数据的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!