小编Jay*_*llo的帖子

如何使用`cv2.putText`正确地在图像上绘制中文文本?(Python的+ OpenCV的)

我使用python cv2(window10,python2.7)在图像中写入文本,当文本是英文时它可以工作,但是当我使用中文文本时它会在图像中写出乱码.

以下是我的代码:

# coding=utf-8
import cv2
import numpy as np

text = "Hello world"   # just work
# text = "??????"  # messy text in the image

cv2.putText(img, text,
            cord,
            font,
            fontScale,
            fontColor,
            lineType)

# Display the image
cv2.imshow("img", img)

cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)

text = "Hello world" # just work下面是输出图像时:

在此输入图像描述

text = "??????" # Chinese text, draw messy text in the image下面是输出图像时:

在此输入图像描述

怎么了?opencv putText不支持其他语言文本吗?

python opencv cv2

8
推荐指数
2
解决办法
6266
查看次数

C ++打印模板容器错误(错误:“ operator <<”的模棱两可的重载)理解了吗?

我想编写模板功能,可以打印容器,如std::vectorstd :: list。

下面是我的函数,只是重载<<

template<typename Container>
std::ostream& operator<<(std::ostream& out, const Container& c){
    for(auto item:c){
        out<<item;
    }
    return out;
}
Run Code Online (Sandbox Code Playgroud)

测试代码如下:

int main(){
    std::vector<int> iVec{5, 9, 1, 4, 6};
    std::cout<<iVec<<std::endl;
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

59146
Run Code Online (Sandbox Code Playgroud)

而且我想在每个值(输出如5 9 1 4 6)中添加一个空格字符串,因此我将函数更改为:

template<typename Container>
std::ostream& operator<<(std::ostream& out, const Container& c){
    for(auto item:c){
        out<<item<<" ";
    }
    return out;
}
Run Code Online (Sandbox Code Playgroud)

然后得到错误:

merror: ambiguous overload for 'operator<<' (operand types are 'std::basic_ostream<char>' and 'const char [2]')
         out<<item<<" ";
Run Code Online (Sandbox Code Playgroud)

我知道<<可以输出普通类型的。 …

c++ c++11

2
推荐指数
1
解决办法
198
查看次数

标签 统计

c++ ×1

c++11 ×1

cv2 ×1

opencv ×1

python ×1