mirror of
https://github.com/nihui/opencv-mobile.git
synced 2025-10-04 16:22:42 +08:00
266 lines
8.0 KiB
Diff
266 lines
8.0 KiB
Diff
diff -Nuarp opencv-2.4.13.7.orig/modules/core/include/opencv2/core/core.hpp opencv-2.4.13.7/modules/core/include/opencv2/core/core.hpp
|
|
--- opencv-2.4.13.7.orig/modules/core/include/opencv2/core/core.hpp 2024-08-03 13:33:29.646494334 +0800
|
|
+++ opencv-2.4.13.7/modules/core/include/opencv2/core/core.hpp 2024-08-03 13:35:12.013094855 +0800
|
|
@@ -2732,6 +2732,37 @@ CV_EXPORTS_W Size getTextSize(const stri
|
|
double fontScale, int thickness,
|
|
CV_OUT int* baseLine);
|
|
|
|
+class FontFaceImpl;
|
|
+class CV_EXPORTS_W FontFace
|
|
+{
|
|
+public:
|
|
+ FontFace();
|
|
+ FontFace(const String& fontPath);
|
|
+
|
|
+ ~FontFace();
|
|
+
|
|
+protected:
|
|
+ void set_glyph(int count, const unsigned int* unicode, const unsigned char* bitmaps);
|
|
+
|
|
+public:
|
|
+ FontFaceImpl* const d;
|
|
+};
|
|
+
|
|
+enum PutTextFlags
|
|
+{
|
|
+ PUT_TEXT_ALIGN_LEFT=0, // put the text to the right from the origin
|
|
+ PUT_TEXT_ALIGN_CENTER=1,// center the text at the origin; not implemented yet
|
|
+ PUT_TEXT_ALIGN_RIGHT=2, // put the text to the left of the origin
|
|
+ PUT_TEXT_ALIGN_MASK=3, // alignment mask
|
|
+ PUT_TEXT_ORIGIN_TL=0,
|
|
+ PUT_TEXT_ORIGIN_BL=32, // treat the target image as having bottom-left origin
|
|
+ PUT_TEXT_WRAP=128 // wrap text to the next line if it does not fit
|
|
+};
|
|
+
|
|
+CV_EXPORTS_W Point putText(InputOutputArray img, const String &text, Point org, Scalar color, const FontFace &fface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range());
|
|
+
|
|
+CV_EXPORTS_W Rect getTextSize(Size imgsize, const String& text, Point org, const FontFace& fontface, int size, int weight=0, PutTextFlags flags=PUT_TEXT_ALIGN_LEFT, Range wrap=Range());
|
|
+
|
|
///////////////////////////////// Mat_<_Tp> ////////////////////////////////////
|
|
|
|
/*!
|
|
diff -Nuarp opencv-2.4.13.7.orig/modules/core/src/drawing.cpp opencv-2.4.13.7/modules/core/src/drawing.cpp
|
|
--- opencv-2.4.13.7.orig/modules/core/src/drawing.cpp 2024-08-03 13:33:29.648494328 +0800
|
|
+++ opencv-2.4.13.7/modules/core/src/drawing.cpp 2024-08-03 14:19:07.916992598 +0800
|
|
@@ -42,6 +42,25 @@
|
|
|
|
namespace cv
|
|
{
|
|
+class FontFaceImpl
|
|
+{
|
|
+public:
|
|
+ FontFaceImpl();
|
|
+
|
|
+public:
|
|
+ int glyph_count;
|
|
+ const unsigned int* glyph_unicode;
|
|
+ const unsigned char* glyph_bitmaps;
|
|
+
|
|
+public:
|
|
+ const unsigned char* get_glyph_bitmap(unsigned int ch) const;
|
|
+};
|
|
+}
|
|
+
|
|
+#include "draw_text.h"
|
|
+
|
|
+namespace cv
|
|
+{
|
|
|
|
enum { XY_SHIFT = 16, XY_ONE = 1 << XY_SHIFT, DRAWING_STORAGE_BLOCK = (1<<12) - 256 };
|
|
|
|
@@ -1992,6 +2011,7 @@ void polylines( Mat& img, const Point**
|
|
}
|
|
|
|
|
|
+#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),
|
|
@@ -2204,12 +2224,41 @@ inline void readCheck(int &c, int &i, co
|
|
if(c >= rightBoundary || c < leftBoundary)
|
|
c = '?';
|
|
}
|
|
+#endif
|
|
|
|
void putText( Mat& img, const string& text, Point org,
|
|
int fontFace, double fontScale, Scalar color,
|
|
int thickness, int line_type, bool bottomLeftOrigin )
|
|
|
|
{
|
|
+ const int fontpixelsize = (fontFace == 1 ? 8 : (fontFace == 5 ? 12 : 20)) * fontScale;
|
|
+ const int base_line = 0;
|
|
+ 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];
|
|
@@ -2264,10 +2313,21 @@ void putText( Mat& img, const string& te
|
|
}
|
|
view_x += dx;
|
|
}
|
|
+#endif
|
|
}
|
|
|
|
Size getTextSize( const string& text, int fontFace, double fontScale, int thickness, int* _base_line)
|
|
{
|
|
+ const int fontpixelsize = (fontFace == 1 ? 8 : (fontFace == 5 ? 12 : 20)) * fontScale;
|
|
+
|
|
+ int w;
|
|
+ int h;
|
|
+ get_text_drawing_size(text.c_str(), fontpixelsize, &w, &h);
|
|
+
|
|
+ if(_base_line) *_base_line = 0;
|
|
+
|
|
+ return Size(w, h);
|
|
+#if 0
|
|
Size size;
|
|
double view_x = 0;
|
|
const char **faces = cv::g_HersheyGlyphs;
|
|
@@ -2294,6 +2354,94 @@ Size getTextSize( const string& text, in
|
|
if( _base_line )
|
|
*_base_line = cvRound(base_line*fontScale + thickness*0.5);
|
|
return size;
|
|
+#endif
|
|
+}
|
|
+
|
|
+FontFaceImpl::FontFaceImpl()
|
|
+{
|
|
+ glyph_count = 0;
|
|
+ glyph_unicode = 0;
|
|
+ glyph_bitmaps = 0;
|
|
+}
|
|
+
|
|
+const unsigned char* FontFaceImpl::get_glyph_bitmap(unsigned int ch) const
|
|
+{
|
|
+ if (!glyph_count || !glyph_unicode || !glyph_bitmaps)
|
|
+ return 0;
|
|
+
|
|
+ for (int i = 0; i < glyph_count; i++)
|
|
+ {
|
|
+ if (glyph_unicode[i] == ch)
|
|
+ return glyph_bitmaps + i * 40 * 20;
|
|
+ }
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
+FontFace::FontFace() : d(new FontFaceImpl)
|
|
+{
|
|
+}
|
|
+
|
|
+FontFace::~FontFace()
|
|
+{
|
|
+ delete d;
|
|
+}
|
|
+
|
|
+void FontFace::set_glyph(int count, const unsigned int* unicode, const unsigned char* bitmaps)
|
|
+{
|
|
+ d->glyph_count = count;
|
|
+ d->glyph_unicode = unicode;
|
|
+ d->glyph_bitmaps = bitmaps;
|
|
+}
|
|
+
|
|
+Point putText(InputOutputArray _img, const String& text, Point org, Scalar color, const FontFace& fontface, int size, int weight, PutTextFlags flags, Range wrap)
|
|
+{
|
|
+ if ( text.empty() )
|
|
+ {
|
|
+ return org;
|
|
+ }
|
|
+ Mat img = _img.getMat();
|
|
+
|
|
+ const int yoffset = org.y - size * 2;
|
|
+
|
|
+ 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, size, _color, fontface);
|
|
+ }
|
|
+ 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, size, _color, fontface);
|
|
+ }
|
|
+ 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, size, _color, fontface);
|
|
+ }
|
|
+
|
|
+ int w;
|
|
+ int h;
|
|
+ get_text_drawing_size(text.c_str(), size, &w, &h, fontface);
|
|
+
|
|
+ return Point(org.x + w, org.y);
|
|
+}
|
|
+
|
|
+Rect getTextSize(Size imgsize, const String& text, Point org, const FontFace& fontface, int size, int weight, PutTextFlags flags, Range wrap)
|
|
+{
|
|
+ int w;
|
|
+ int h;
|
|
+ get_text_drawing_size(text.c_str(), size, &w, &h, fontface);
|
|
+
|
|
+ return Rect(org.x, org.y - size * 2, w, h);
|
|
}
|
|
|
|
}
|
|
@@ -2679,7 +2827,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-2.4.13.7.orig/modules/core/src/tables.cpp opencv-2.4.13.7/modules/core/src/tables.cpp
|
|
--- opencv-2.4.13.7.orig/modules/core/src/tables.cpp 2024-08-03 13:33:29.648494328 +0800
|
|
+++ opencv-2.4.13.7/modules/core/src/tables.cpp 2024-08-03 13:33:44.160445806 +0800
|
|
@@ -204,6 +204,7 @@ const uchar g_Saturate8u[] =
|
|
255
|
|
};
|
|
|
|
+#if 0
|
|
const char* g_HersheyGlyphs[] = {
|
|
"",
|
|
"MWRMNV RMVV PSTS",
|
|
@@ -3506,6 +3507,7 @@ const char* g_HersheyGlyphs[] = {
|
|
"",
|
|
"",
|
|
0 };
|
|
+#endif
|
|
|
|
}
|
|
|