beg the boss to help me solve the coding problem. GBK? UTF-8?
I haven"t been playing Python for long. I feel that UTF-8 is omnipotent. Sometimes I report an error, and I can still use it when I change it to GBK.
however, this time, I want to solve this problem, So knelt down and begged the boss to help me explain the coding problem.
this is the problem I encountered. When using OpenCV to achieve module matching, the name of the window is always garbled
-sharp -*- coding:UTF-8 -*-
import cv2 as cv
import numpy as np
-sharp
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()
garbled in the upper left corner
:
is it the wrong encoding, or the openCV, or the compiler? The compiler is VSCODE, to ask for the boss"s solution