天天看點

cv2.imread 中文路徑傳回null

經過測試,發現cv2.imread讀取圖檔,路徑中有中文,則傳回null

cv2.imread 中文路徑傳回null

這個方法還沒試:

  1. file = askopenfilename()
  2. im2 = cv2.imread(file.encode('gbk')

opencv c++是支援中文的,python不支援中文。

讀取圖檔

import cv2
img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 1)
img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), -1)  # 讀入完整圖檔,見下面解釋

img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 0)  # 讀成灰階

img = cv2.imdecode(np.fromfile(img_path, dtype=np.uint8), 1)  # 讀成彩圖
           

繼續閱讀