OSD优化

serial
Matthew 2 years ago
parent eb35f63109
commit 9782a10e32

@ -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<OSD_INFO>::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 <int> compression_params;

Loading…
Cancel
Save