最終解決效果:

解決方法:通過指定編碼返回字符串
def zh_cn(string):
return string.encode('gb2312').decode(errors='ignore')
完整示例代碼:
# -*- coding: utf-8 -*-
import cv2
import sys
print(cv2.__version__)
def zh_cn(string):
return string.encode('gb2312').decode(errors='ignore')
if __name__ =="__main__":
if len(sys.argv) > 1 :
img = cv2.imread(sys.argv[1],cv2.IMREAD_ANYCOLOR)
cv2.imshow(zh_cn("使用opencv-python顯示圖片"),img)
cv2.waitKey(0)
cv2.destroyAllWindows()
else:
print(zh_cn("使用方法: python firstCV.py 圖片文件名完整路徑(如:d:/test.png)"))
img = cv2.imread("C:\\Users\\devel\\Desktop\\test.png",cv2.IMREAD_ANYCOLOR)
cv2.imshow(zh_cn("使用opencv-python顯示圖片,使用默認圖片test.png"),img)
cv2.waitKey(0)
cv2.destroyAllWindows()
c++默認支持中文,直接調用imshow可顯示

C++示例代碼:文章來源:http://www.zghlxwxcb.cn/news/detail-506773.html
#include <opencv.hpp>
#include <highgui/highgui.hpp>
using namespace cv;
int main(int argc, char* argv[])
{
Mat img = imread(argv[1],IMREAD_ANYCOLOR);
if (!img.data)
return -1;
imshow("調用imread讀取的原圖數據", img);
waitKey(0);
return 0;
}
命令行執(zhí)行python代碼:文章來源地址http://www.zghlxwxcb.cn/news/detail-506773.html

到了這里,關于opencv顯示圖像中文標題亂碼解決的文章就介紹完了。如果您還想了解更多內容,請在右上角搜索TOY模板網以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網!