From 4de8b2ec798a642baf7a4f5950eb6bed48995410 Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Mon, 19 Feb 2024 09:13:55 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96osd=E7=BB=98=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 33f5baad..3fd3d05c 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -939,12 +939,22 @@ void DrawOutlineText(cv::Ptr ft2, cv::Mat& mat, const std::st for (std::vector::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); }