优化osd绘制

serial
BlueMatthew 1 year ago
parent 8ae6c05533
commit 4de8b2ec79

@ -939,12 +939,22 @@ 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 )
{
textSize = ft2->getTextSize(*it, fontSize, thickness, &baseline);
lineHeight = std::max(lineHeight, textSize.height);
lineHeight = std::max(fontSize, textSize.height);
ft2->putText(mat, *it, pt, fontSize, clr, thickness, cv::LINE_AA, false, true);
#ifdef _DEBUG
if (pt.y > (mat.rows / 2))
{
ft2->putText(mat, *it, cv::Point(pt.x, pt.y - fontSize * 3), fontSize, clr, thickness, cv::LINE_AA, false);
}
else
{
ft2->putText(mat, *it, cv::Point(pt.x, pt.y + fontSize * 3), fontSize, clr, thickness, cv::LINE_AA, false);
}
#endif
pt.x = startPoint.x;
pt.y += lineHeight > 0 ? (lineHeight + fontSize / 5) : 0;
pt.y += lineHeight + (lineHeight >> 2); // 125%
}
}
@ -1023,6 +1033,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
int thickness = (int)(4.0 * ratio);
if (thickness < 2) thickness = 2;
else if (thickness > 4) thickness = 4;
cv::Scalar scalar(255, 255, 255); // white
@ -1050,7 +1061,7 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
NdkCamera::CAPTURE_RESULT captureResult = mCamera->getCaptureResult();
char str[128] = { 0 };
snprintf(str, sizeof(str), "通道 AE=%u EXPS=%ums ISO=%d AF=%u FD=%.3f AFS=%u HDR=%d", captureResult.autoExposure,
snprintf(str, sizeof(str), "AE=%u EXPS=%ums ISO=%d AF=%u FD=%.3f AFS=%u HDR=%d", captureResult.autoExposure,
(unsigned int)(captureResult.exposureTime / 1000000),
captureResult.sensitibity,
captureResult.autoFocus,
@ -1060,7 +1071,8 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
// cv::putText(mat, str, cv::Point(0, mat.rows - 20), cv::FONT_HERSHEY_COMPLEX, fontScale, scalar, thickness1, cv::LINE_AA);
ft2->putText(mat, str, cv::Point(0, mat.rows - fontSize - 20),
textSize = ft2->getTextSize(str, fontSize, -1, &baseline);
ft2->putText(mat, str, cv::Point(0, mat.rows - fontSize - 20 * ratio),
fontSize, scalarRed, -1, cv::LINE_AA, false);
// text.putText(mat, str.c_str(), cv::Point(0, mat.rows - 20), scalar);
@ -1110,6 +1122,9 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
pt.x = it->x * ratio;
pt.y = height - it->y * ratio - textSize.height;
}
cv::Rect rc(pt.x, pt.y, textSize.width, textSize.height);
cv::rectangle(mat, rc, cv::Scalar(0,255,255), 2);
DrawOutlineText(ft2, mat, it->text, pt, fontSize, scalar, thickness);
}

Loading…
Cancel
Save