跪求大佬帮我解决编码问题??GBK???UTF-8????
我玩Python也不久了, 感觉UTF-8是万能的, 有时报错, 改成GBK也还能用......
然而这次, 我想解决这个问题, So跪求大佬帮我解释下编码的问题。
这是我遇到的问题, 用OpenCV去实现模块匹配时, 窗口的名字总是乱码
# -*- coding:UTF-8 -*-
import cv2 as cv
import numpy as np
# 模板匹配
def template_image():
tpl = cv.imread(r'D:\pic\2.png')
target = cv.imread(r'D:\pic\1.jpg')
cv.imshow('tpl',tpl)
cv.imshow('target',target)
methods = [cv.TM_SQDIFF_NORMED, cv.TM_CCORR_NORMED, cv.TM_CCOEFF_NORMED]
th, tw = tpl.shape[:2]
for md in methods:
print(md)
result = cv.matchTemplate(target, tpl, md)
min_val, max_val, min_loc, max_loc = cv.minMaxLoc(result)
if md == cv.TM_SQDIFF_NORMED:
t1 = min_loc
else:
t1 = max_loc
br = (t1[0]+tw, t1[1]+th)
cv.rectangle(target, t1, br, (0, 0, 255), 2)
cv.imshow('匹配'+str(md), target)
template_image()
cv.waitKey(0)
cv.destroyAllWindows()
左上角乱码
将注释改为:
# -*- coding:GBK -*-
依旧乱码
究竟是编码没选对, 还是openCV的关系, 或者是编译器的关系???编译器是VSCODE, 求大佬解答