cv_put_Text.hpp 717 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#pragma once
#include <ft2build.h>
#include FT_FREETYPE_H
#include <opencv2/opencv.hpp>

class PutText {
private:
    FT_Library ft;
    FT_Face face;
public:
    PutText(const char* font_path);
    ~PutText();

    /**
     * @brief 向图片写文字(支持中文)
     * @param img    待叠加字符的图片
     * @param text     待叠加的字符
     * @param x        垂直方向缩放比例
     * @param y        水平方向缩放比例
     * @param fontSize 原始图像
     * @param color    字体颜色,默认绿色
     * 
     * @return  无返回值
     */
    void putText(cv::Mat& img, const std::string& text, int x, int y, int fontSize=2, cv::Scalar color=cv::Scalar(0, 255, 0));
};