From 9782a10e32d7290e12257c1a804375e4c67c3e80 Mon Sep 17 00:00:00 2001 From: Matthew Date: Fri, 3 Nov 2023 16:31:16 +0800 Subject: [PATCH] =?UTF-8?q?OSD=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/PhoneDevice.cpp | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/app/src/main/cpp/PhoneDevice.cpp b/app/src/main/cpp/PhoneDevice.cpp index 432418c4..b4c2fafa 100644 --- a/app/src/main/cpp/PhoneDevice.cpp +++ b/app/src/main/cpp/PhoneDevice.cpp @@ -648,22 +648,26 @@ bool CPhoneDevice::OnImageReady(const cv::Mat& mat) double fontScale = 1; // base 1024 double height = mat.size().height; double width = mat.size().width; - double ratio = std::min(height / 1024, width / 1920); + // double ratio = std::min(height / 1024, width / 1920); + double ratio = std::sqrt((height * width) / (1024.0 * 1920.0)); fontScale = fontScale * ratio; int thickness2 = 1 * ratio; if (thickness2 == 0) thickness2 = 1; - int thickness1 = thickness2 + 1; + int thickness1 = thickness2 + 3; cv::Scalar scalar1(0, 0, 0); // black cv::Scalar scalar2(255, 255, 255); // white + cv::Scalar bgScalar(255, 255, 255); // white cv::Point pt1, pt2; for (vector::const_iterator it = mOsds.cbegin(); it != mOsds.cend(); ++it) { - textSize = cv::getTextSize(it->text, cv::FONT_HERSHEY_COMPLEX, fontScale, thickness1, &baseline); - textSize2 = cv::getTextSize(it->text, cv::FONT_HERSHEY_COMPLEX, fontScale, thickness2, &baseline); - - ALOGE("putText: w1=%d w2=%d tn=%d/%d", textSize.width, textSize2.width, thickness1, thickness2); + if (it->text.empty()) + { + continue; + } + textSize = cv::getTextSize(it->text, cv::FONT_HERSHEY_SIMPLEX, fontScale, thickness1, &baseline); + textSize2 = cv::getTextSize(it->text, cv::FONT_HERSHEY_SIMPLEX, fontScale, thickness2, &baseline); if (it->alignment == OSD_ALIGNMENT_TOP_LEFT) { @@ -686,8 +690,19 @@ bool CPhoneDevice::OnImageReady(const cv::Mat& mat) pt1.y = height - it->y * ratio; } + cv::Point pt = pt1; + pt.x += textSize.width; + pt.y -= textSize.height; + + // cv::rectangle(mat, pt1, pt, scalar2, -1); + pt2 = pt1; + pt2.y += textSize.height; + + ALOGE("putText: fontScale=%f w1=%d w2=%d tn=%d/%d", fontScale, textSize.width, textSize2.width, thickness1, thickness2); + cv::putText(mat, it->text, pt1, cv::FONT_HERSHEY_COMPLEX, fontScale, scalar1, thickness1,cv::LINE_AA); cv::putText(mat, it->text, pt1, cv::FONT_HERSHEY_COMPLEX, fontScale, scalar2, thickness2,cv::LINE_AA); + } vector compression_params;