首页 > 其他分享 >在OpenCV图片(cv::Mat格式)输出汉字

在OpenCV图片(cv::Mat格式)输出汉字

时间:2023-02-14 21:46:26浏览次数:48  
标签:Mat image inColor OpenCV inMat painter cv QImage

static void putTextZH(const cv::Mat &inMat, const QString text, const cv::Point wordCenter, int inWordSize, const cv::Scalar inColor)
{
QImage image;
switch (inMat.type())
{
case CV_8UC1:
image = QImage(inMat.data, inMat.cols, inMat.rows, inMat.cols, QImage::Format_Mono);
break;
case CV_8UC3:
image = QImage(inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_RGB888);
break;
case CV_8UC4:
image = QImage(inMat.data, inMat.cols, inMat.rows, inMat.step, QImage::Format_ARGB32);
break;
}
QColor drawColor(inColor[0], inColor[1], inColor[2]);//调用时,inColor使用CV_RGB(0, 0, 255)格式颜色
QPainter painter(&image);
QPen pen = QPen(drawColor, inWordSize);
QBrush brush = QBrush(drawColor);
painter.setPen(pen);
painter.setBrush(brush);
QFont font("微软雅黑", inWordSize);
painter.setFont(font);
painter.drawText(QPoint(wordCenter.x, wordCenter.y), text);
}

标签:Mat,image,inColor,OpenCV,inMat,painter,cv,QImage
From: https://www.cnblogs.com/zdt168/p/17120975.html

相关文章