优化文字绘制

serial
BlueMatthew 1 year ago
parent a3ec2f43c3
commit 429f15455c

@ -552,7 +552,8 @@ namespace cv {
{ {
continue; continue;
} }
mat.at<Vec3b>(row, col) = outlineColor; // mat.at<Vec3b>(row, col) = outlineColor;
putPixel_8UC3_blend(mat, row, col, &(outlineColor[0]), s->coverage);
} }
} }
@ -573,7 +574,8 @@ namespace cv {
{ {
continue; continue;
} }
mat.at<Vec3b>(row, col) = fontColor; // mat.at<Vec3b>(row, col) = fontColor;
putPixel_8UC3_blend(mat, row, col, &(fontColor[0]), s->coverage);
#if 0 #if 0
Pixel32 &dst = Pixel32 &dst =
pxl[(int)( pxl[(int)(
@ -732,7 +734,7 @@ namespace cv {
// Calcurate width/height/baseline ( in OpenCV coordinates ) // Calcurate width/height/baseline ( in OpenCV coordinates )
int width = xMax - xMin; int width = xMax - xMin;
int height = -yMin; int height = yMax;
if (_thickness > 0) { if (_thickness > 0) {
width = cvRound(width + _thickness * 2); width = cvRound(width + _thickness * 2);
@ -744,10 +746,10 @@ namespace cv {
} }
if (_baseLine) { if (_baseLine) {
*_baseLine = yMax; *_baseLine = -yMin;
} }
return Size(width, height + yMax); return Size(width, height);
} }

@ -939,7 +939,7 @@ void DrawOutlineText(cv::Ptr<cv::ft::FreeType2> ft2, cv::Mat& mat, const std::st
for (std::vector<std::string>::const_iterator it = lines.cbegin(); it != lines.cend(); ++it ) for (std::vector<std::string>::const_iterator it = lines.cbegin(); it != lines.cend(); ++it )
{ {
textSize = ft2->getTextSize(*it, fontSize, thickness, &baseline); textSize = ft2->getTextSize(*it, fontSize, thickness, &baseline);
lineHeight = std::max(fontSize, textSize.height); lineHeight = std::max(fontSize, textSize.height + baseline);
ft2->putText(mat, *it, pt, fontSize, clr, thickness, cv::LINE_AA, false, true); ft2->putText(mat, *it, pt, fontSize, clr, thickness, cv::LINE_AA, false, true);
@ -952,7 +952,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
{ {
if (mCamera == NULL) if (mCamera == NULL)
{ {
int aa = 0; // int aa = 0;
return false; return false;
} }
@ -1060,7 +1060,6 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
captureResult.hdrMode); captureResult.hdrMode);
// cv::putText(mat, str, cv::Point(0, mat.rows - 20), cv::FONT_HERSHEY_COMPLEX, fontScale, scalar, thickness1, cv::LINE_AA); // cv::putText(mat, str, cv::Point(0, mat.rows - 20), cv::FONT_HERSHEY_COMPLEX, fontScale, scalar, thickness1, cv::LINE_AA);
textSize = ft2->getTextSize(str, fontSize, -1, &baseline); textSize = ft2->getTextSize(str, fontSize, -1, &baseline);
ft2->putText(mat, str, cv::Point(0, mat.rows - fontSize - 20 * ratio), ft2->putText(mat, str, cv::Point(0, mat.rows - fontSize - 20 * ratio),
fontSize, scalarRed, -1, cv::LINE_AA, false); fontSize, scalarRed, -1, cv::LINE_AA, false);
@ -1105,12 +1104,12 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
else if (it->alignment == OSD_ALIGNMENT_BOTTOM_RIGHT) else if (it->alignment == OSD_ALIGNMENT_BOTTOM_RIGHT)
{ {
pt.x = width - textSize.width - it->x * ratio; pt.x = width - textSize.width - it->x * ratio;
pt.y = height - it->y * ratio - textSize.height; pt.y = height - it->y * ratio - textSize.height - baseline;
} }
else if (it->alignment == OSD_ALIGNMENT_BOTTOM_LEFT) else if (it->alignment == OSD_ALIGNMENT_BOTTOM_LEFT)
{ {
pt.x = it->x * ratio; pt.x = it->x * ratio;
pt.y = height - it->y * ratio - textSize.height; pt.y = height - it->y * ratio - textSize.height - baseline;
} }
// cv::Rect rc(pt.x, pt.y, textSize.width, textSize.height); // cv::Rect rc(pt.x, pt.y, textSize.width, textSize.height);

Loading…
Cancel
Save