Skip to content

Commit 4c71dd0

Browse files
authored
Puttext docs (nihui#136)
1 parent b71dcfe commit 4c71dd0

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
:heavy_check_mark: All the binaries are compiled from source on github action, **no virus**, **no backdoor**, **no secret code**.
2525

26+
:heavy_check_mark: ***NEW FEATURE*** [`cv::putText` supports full-width CJK characters](#cvputtext-supports-full-width-cjk-characters)
27+
2628
|opencv 4.10.0 package size|The official opencv|opencv-mobile|
2729
|:-:|:-:|:-:|
2830
|source zip|95.2 MB|8.25 MB|
@@ -481,6 +483,40 @@ zip -r -9 opencv-mobile-4.10.0-mypackage.zip install
481483

482484
* 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
483485

486+
## `cv::putText` supports full-width CJK characters
487+
488+
1. Open https://nihui.github.io/opencv-mobile/patches/fontface.html or `opencv-mobile-X.Y.Z/fontface.html` in your browser.
489+
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.
490+
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.
491+
492+
Since all characters have been converted to embedded bitmap, the drawing routine does not depend on freetype library or any font files at runtime.
493+
494+
```cpp
495+
#include <opencv2/core/core.hpp>
496+
#include <opencv2/highgui/highgui.hpp>
497+
#include <opencv2/imgproc/imgproc.hpp>
498+
#include "myfontface.h"
499+
500+
int main()
501+
{
502+
cv::Mat bgr = cv::imread("atari.jpg", 1);
503+
504+
// use this font
505+
MyFontFace myfont;
506+
507+
// draw full-width text with myfont
508+
const char* zhtext = "称呼机器人为破铜烂铁,\n违反了禁止歧视机器人法!";
509+
cv::putText(bgr, zhtext, cv::Point(30, 250), cv::Scalar(127, 0, 127), myfont, 20);
510+
511+
// get bounding rect
512+
cv::Rect rr = cv::getTextSize(bgr.size(), zhtext, cv::Point(30, 250), myfont, 20);
513+
514+
cv::imwrite("out.jpg", bgr);
515+
516+
return 0;
517+
}
518+
```
519+
484520
# opencv modules included
485521

486522
|module|comment|

0 commit comments

Comments
 (0)