Puttext docs (#136)

This commit is contained in:
nihui
2024-08-03 17:33:14 +08:00
committed by GitHub
parent b71dcfe02f
commit 4c71dd0f9c

View File

@@ -23,6 +23,8 @@
:heavy_check_mark: All the binaries are compiled from source on github action, **no virus**, **no backdoor**, **no secret code**.
:heavy_check_mark: ***NEW FEATURE*** [`cv::putText` supports full-width CJK characters](#cvputtext-supports-full-width-cjk-characters)
|opencv 4.10.0 package size|The official opencv|opencv-mobile|
|:-:|:-:|:-:|
|source zip|95.2 MB|8.25 MB|
@@ -481,6 +483,40 @@ zip -r -9 opencv-mobile-4.10.0-mypackage.zip install
* C++ RTTI and exceptions are disabled for minimal build on mobile platforms and webassembly build. Be careful when you write ```cv::Mat roi = image(roirect);``` :P
## `cv::putText` supports full-width CJK characters
1. Open https://nihui.github.io/opencv-mobile/patches/fontface.html or `opencv-mobile-X.Y.Z/fontface.html` in your browser.
2. In the opened page, enter all the text to be drawn, select the TTF font file (optional), click the `Convert to Font Header` button to download the fontface header. This step is completely local operation, without connecting to a remote server, your data is private and safe.
3. Include the generated fontface header, initialize a fontface instance, and pass it as the argument to `cv::putText`. The source file must be encoded in UTF-8.
Since all characters have been converted to embedded bitmap, the drawing routine does not depend on freetype library or any font files at runtime.
```cpp
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include "myfontface.h"
int main()
{
cv::Mat bgr = cv::imread("atari.jpg", 1);
// use this font
MyFontFace myfont;
// draw full-width text with myfont
const char* zhtext = "称呼机器人为破铜烂铁,\n违反了禁止歧视机器人法!";
cv::putText(bgr, zhtext, cv::Point(30, 250), cv::Scalar(127, 0, 127), myfont, 20);
// get bounding rect
cv::Rect rr = cv::getTextSize(bgr.size(), zhtext, cv::Point(30, 250), myfont, 20);
cv::imwrite("out.jpg", bgr);
return 0;
}
```
# opencv modules included
|module|comment|