QImage MainWindow::Mat2QImage(const cv::Mat& InputMat)
{
cv::Mat TmpMat;
// convert the color space to RGB
if (InputMat.channels() == 1)
{
cv::cvtColor(InputMat, TmpMat, CV_GRAY2RGB);
Result=QImage((const uchar*)(TmpMat.data), TmpMat.cols, TmpMat.rows,TmpMat.cols*TmpMat.channels(),
QImage::Format_Indexed8);
}
else
{
cv::cvtColor(InputMat, TmpMat, CV_BGR2RGB);
// construct the QImage using the data of the mat, while do not copy the data
Result = QImage((const uchar*)(TmpMat.data), TmpMat.cols, TmpMat.rows,TmpMat.cols*TmpMat.channels(),
QImage::Format_RGB888);
}
// deep copy the data from mat to QImage
Result.bits();
return Result;
}
无误的Mat2QImage代码
最新推荐文章于 2022-09-02 09:06:08 发布