The name of the window is always garbled, begging the boss to help me solve the coding problem. GBK? UTF-8? Something to do with openCV?

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

Nov.03,2021

is always like this. Let's use English as the title.

< hr >

solution: first encode Unicode as GBK , and then decode it to utf-8

.
img = cv.imread('test.jpg')
cv.imshow(''.encode('gbk').decode(), img)
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3acad-4d8de.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3acad-4d8de.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?