我使用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不支持其他语言文本吗?
我想编写模板功能,可以打印容器,如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)
我知道<<可以输出普通类型的。 …