From db9047a97d3e745248024833491d2916a2300c2b Mon Sep 17 00:00:00 2001 From: BlueMatthew Date: Sat, 10 Feb 2024 23:52:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81=E6=A0=BC?= =?UTF-8?q?=E5=BC=8F=EF=BC=88VS=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/cpp/CvText.h | 177 +++++++++++++++++++------------------- 1 file changed, 89 insertions(+), 88 deletions(-) diff --git a/app/src/main/cpp/CvText.h b/app/src/main/cpp/CvText.h index 66b205dd..979ecc8f 100644 --- a/app/src/main/cpp/CvText.h +++ b/app/src/main/cpp/CvText.h @@ -11,125 +11,126 @@ #include namespace cv { -namespace ft { + namespace ft { - using cv::String; - // using cv::CV_Assert; + using cv::String; + // using cv::CV_Assert; - class FreeType2 : public Algorithm - { - public: - /** @brief Load font data. + class FreeType2 : public Algorithm + { + public: + /** @brief Load font data. -The function loadFontData loads font data. + The function loadFontData loads font data. -@param fontFileName FontFile Name -@param idx face_index to select a font faces in a single file. -*/ + @param fontFileName FontFile Name + @param idx face_index to select a font faces in a single file. + */ - virtual void loadFontData(String fontFileName, int idx) = 0; + virtual void loadFontData(String fontFileName, int idx) = 0; -/** @brief Set Split Number from Bezier-curve to line + /** @brief Set Split Number from Bezier-curve to line -The function setSplitNumber set the number of split points from bezier-curve to line. -If you want to draw large glyph, large is better. -If you want to draw small glyph, small is better. + The function setSplitNumber set the number of split points from bezier-curve to line. + If you want to draw large glyph, large is better. + If you want to draw small glyph, small is better. -@param num number of split points from bezier-curve to line -*/ + @param num number of split points from bezier-curve to line + */ - virtual void setSplitNumber( int num ) = 0; + virtual void setSplitNumber(int num) = 0; -/** @brief Draws a text string. + /** @brief Draws a text string. -The function putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by "Tofu" or non-drawn. + The function putText renders the specified text string in the image. Symbols that cannot be rendered using the specified font are replaced by "Tofu" or non-drawn. -@param img Image. (Only 8UC1/8UC3/8UC4 2D mat is supported.) -@param text Text string to be drawn. -@param org Bottom-left/Top-left corner of the text string in the image. -@param fontHeight Drawing font size by pixel unit. -@param color Text color. -@param thickness Thickness of the lines used to draw a text when negative, the glyph is filled. Otherwise, the glyph is drawn with this thickness. -@param line_type Line type. See the line for details. -@param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner. -*/ + @param img Image. (Only 8UC1/8UC3/8UC4 2D mat is supported.) + @param text Text string to be drawn. + @param org Bottom-left/Top-left corner of the text string in the image. + @param fontHeight Drawing font size by pixel unit. + @param color Text color. + @param thickness Thickness of the lines used to draw a text when negative, the glyph is filled. Otherwise, the glyph is drawn with this thickness. + @param line_type Line type. See the line for details. + @param bottomLeftOrigin When true, the image data origin is at the bottom-left corner. Otherwise, it is at the top-left corner. + */ - virtual void putText( - InputOutputArray img, const String& text, Point org, - int fontHeight, Scalar color, - int thickness, int line_type, bool bottomLeftOrigin - ) = 0; + virtual void putText( + InputOutputArray img, const String& text, Point org, + int fontHeight, Scalar color, + int thickness, int line_type, bool bottomLeftOrigin + ) = 0; -/** @brief Calculates the width and height of a text string. + /** @brief Calculates the width and height of a text string. -The function getTextSize calculates and returns the approximate size of a box that contains the specified text. -That is, the following code renders some text, the tight box surrounding it, and the baseline: : -@code - String text = "Funny text inside the box"; - int fontHeight = 60; - int thickness = -1; - int linestyle = LINE_8; + The function getTextSize calculates and returns the approximate size of a box that contains the specified text. + That is, the following code renders some text, the tight box surrounding it, and the baseline: : + @code + String text = "Funny text inside the box"; + int fontHeight = 60; + int thickness = -1; + int linestyle = LINE_8; - Mat img(600, 800, CV_8UC3, Scalar::all(0)); + Mat img(600, 800, CV_8UC3, Scalar::all(0)); - int baseline=0; + int baseline=0; - cv::Ptr ft2; - ft2 = cv::freetype::createFreeType2(); - ft2->loadFontData( "./mplus-1p-regular.ttf", 0 ); + cv::Ptr ft2; + ft2 = cv::freetype::createFreeType2(); + ft2->loadFontData( "./mplus-1p-regular.ttf", 0 ); - Size textSize = ft2->getTextSize(text, - fontHeight, - thickness, - &baseline); + Size textSize = ft2->getTextSize(text, + fontHeight, + thickness, + &baseline); - if(thickness > 0){ - baseline += thickness; - } + if(thickness > 0){ + baseline += thickness; + } - // center the text - Point textOrg((img.cols - textSize.width) / 2, - (img.rows + textSize.height) / 2); + // center the text + Point textOrg((img.cols - textSize.width) / 2, + (img.rows + textSize.height) / 2); - // draw the box - rectangle(img, textOrg + Point(0, baseline), - textOrg + Point(textSize.width, -textSize.height), - Scalar(0,255,0),1,8); + // draw the box + rectangle(img, textOrg + Point(0, baseline), + textOrg + Point(textSize.width, -textSize.height), + Scalar(0,255,0),1,8); - // ... and the baseline first - line(img, textOrg + Point(0, thickness), - textOrg + Point(textSize.width, thickness), - Scalar(0, 0, 255),1,8); + // ... and the baseline first + line(img, textOrg + Point(0, thickness), + textOrg + Point(textSize.width, thickness), + Scalar(0, 0, 255),1,8); - // then put the text itself - ft2->putText(img, text, textOrg, fontHeight, - Scalar::all(255), thickness, linestyle, true ); -@endcode + // then put the text itself + ft2->putText(img, text, textOrg, fontHeight, + Scalar::all(255), thickness, linestyle, true ); + @endcode -@param text Input text string. -@param fontHeight Drawing font size by pixel unit. -@param thickness Thickness of lines used to render the text. See putText for details. -@param[out] baseLine y-coordinate of the baseline relative to the bottom-most text -point. -@return The size of a box that contains the specified text. + @param text Input text string. + @param fontHeight Drawing font size by pixel unit. + @param thickness Thickness of lines used to render the text. See putText for details. + @param[out] baseLine y-coordinate of the baseline relative to the bottom-most text + point. + @return The size of a box that contains the specified text. -@see cv::putText - */ - virtual Size getTextSize(const String& text, - int fontHeight, int thickness, - CV_OUT int* baseLine) = 0; + @see cv::putText + */ + virtual Size getTextSize(const String& text, + int fontHeight, int thickness, + CV_OUT int* baseLine) = 0; - }; + }; -/** @brief Create FreeType2 Instance + /** @brief Create FreeType2 Instance -The function createFreeType2 create instance to draw UTF-8 strings. + The function createFreeType2 create instance to draw UTF-8 strings. -*/ - Ptr createFreeType2(); + */ + Ptr createFreeType2(); -//! @} -} } // namespace freetype + //! @} + } +} // namespace freetype #endif // _OPENCV_CVText_