1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-30 15:53:03 +04:00

Added getFontScaleFromHeight()

This commit is contained in:
Philipp Hasper
2018-01-11 13:27:16 +01:00
parent 64a9e92390
commit 6032d86e23
2 changed files with 25 additions and 0 deletions
+11
View File
@@ -2364,6 +2364,17 @@ Size getTextSize( const String& text, int fontFace, double fontScale, int thickn
return size;
}
double getFontScaleFromHeight(const int fontFace, const int pixelHeight, const int thickness)
{
// By https://stackoverflow.com/a/27898487/1531708
const int* ascii = getFontData(fontFace);
int base_line = (ascii[0] & 15);
int cap_line = (ascii[0] >> 4) & 15;
return static_cast<double>(pixelHeight - static_cast<double>((thickness + 1)) / 2.0) / static_cast<double>(cap_line + base_line);
}
}