diff -Nuarp opencv-4.8.1.orig/modules/imgproc/src/drawing.cpp opencv-4.8.1/modules/imgproc/src/drawing.cpp --- opencv-4.8.1.orig/modules/imgproc/src/drawing.cpp 2023-09-27 18:18:31.000000000 +0800 +++ opencv-4.8.1/modules/imgproc/src/drawing.cpp 2023-12-09 17:24:35.811627301 +0800 @@ -40,6 +40,8 @@ //M*/ #include "precomp.hpp" +#include "draw_text.h" + namespace cv { @@ -2074,6 +2076,7 @@ void polylines( InputOutputArray _img, c } +#if 0 enum { FONT_SIZE_SHIFT=8, FONT_ITALIC_ALPHA=(1 << 8), FONT_ITALIC_DIGIT=(2 << 8), FONT_ITALIC_PUNCT=(4 << 8), FONT_ITALIC_BRACES=(8 << 8), FONT_HAVE_GREEK=(16 << 8), @@ -2288,6 +2291,7 @@ inline void readCheck(int &c, int &i, co } extern const char* g_HersheyGlyphs[]; +#endif void putText( InputOutputArray _img, const String& text, Point org, int fontFace, double fontScale, Scalar color, @@ -2301,6 +2305,35 @@ void putText( InputOutputArray _img, con return; } Mat img = _img.getMat(); + + const int fontpixelsize = 8 * fontScale; + const int base_line = 4 * fontScale; + const int yoffset = bottomLeftOrigin ? img.rows - org.y - fontpixelsize * 2 + base_line : org.y - fontpixelsize * 2 + base_line; + + unsigned int _color = 0; + unsigned char* border_color = (unsigned char*)&_color; + + if (img.channels() == 1) + { + border_color[0] = color[0]; + draw_text_c1(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); + } + else if (img.channels() == 3) + { + border_color[0] = color[0]; + border_color[1] = color[1]; + border_color[2] = color[2]; + draw_text_c3(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); + } + else if (img.channels() == 4) + { + border_color[0] = color[0]; + border_color[1] = color[1]; + border_color[2] = color[2]; + border_color[3] = color[3]; + draw_text_c4(img.data, img.cols, img.rows, text.c_str(), org.x, yoffset, fontpixelsize, _color); + } +#if 0 const int* ascii = getFontData(fontFace); double buf[4]; @@ -2355,10 +2388,21 @@ void putText( InputOutputArray _img, con } view_x += dx; } +#endif } Size getTextSize( const String& text, int fontFace, double fontScale, int thickness, int* _base_line) { + const int fontpixelsize = 8 * fontScale; + + int w; + int h; + get_text_drawing_size(text.c_str(), fontpixelsize, &w, &h); + + *_base_line = 4 * fontScale; + + return Size(w, h); +#if 0 Size size; double view_x = 0; const char **faces = cv::g_HersheyGlyphs; @@ -2385,10 +2429,13 @@ Size getTextSize( const String& text, in if( _base_line ) *_base_line = cvRound(base_line*fontScale + thickness*0.5); return size; +#endif } double getFontScaleFromHeight(const int fontFace, const int pixelHeight, const int thickness) { + return pixelHeight / 16.0; +#if 0 // By https://stackoverflow.com/a/27898487/1531708 const int* ascii = getFontData(fontFace); @@ -2396,6 +2443,7 @@ double getFontScaleFromHeight(const int int cap_line = (ascii[0] >> 4) & 15; return static_cast(pixelHeight - static_cast((thickness + 1)) / 2.0) / static_cast(cap_line + base_line); +#endif } } @@ -2897,7 +2945,7 @@ cvInitFont( CvFont *font, int font_face, { CV_Assert( font != 0 && hscale > 0 && vscale > 0 && thickness >= 0 ); - font->ascii = cv::getFontData(font_face); + font->ascii = 0; font->font_face = font_face; font->hscale = (float)hscale; font->vscale = (float)vscale; diff -Nuarp opencv-4.8.1.orig/modules/imgproc/src/hershey_fonts.cpp opencv-4.8.1/modules/imgproc/src/hershey_fonts.cpp --- opencv-4.8.1.orig/modules/imgproc/src/hershey_fonts.cpp 2023-09-27 18:18:31.000000000 +0800 +++ opencv-4.8.1/modules/imgproc/src/hershey_fonts.cpp 2023-12-09 17:22:38.027235607 +0800 @@ -51,6 +51,7 @@ namespace cv { +#if 0 const char* g_HersheyGlyphs[] = { "", "MWRMNV RMVV PSTS", @@ -3353,6 +3354,7 @@ const char* g_HersheyGlyphs[] = { "", "", 0 }; +#endif }