問題描述
cv2.imread路徑為中文時傳回None。
方案
讀取(先用np.fromfile讀取為np.uint8格式,再使用cv2.imdecode解碼):
# 檔案路徑file_path,傳回讀取後的圖檔
cv_img = cv2.imdecode(np.fromfile(file_path,dtype=np.uint8),-1)
cv2.imencode('.jpg',img)[1].tofile(file_path)
cv2.imread路徑為中文時傳回None。
讀取(先用np.fromfile讀取為np.uint8格式,再使用cv2.imdecode解碼):
# 檔案路徑file_path,傳回讀取後的圖檔
cv_img = cv2.imdecode(np.fromfile(file_path,dtype=np.uint8),-1)
cv2.imencode('.jpg',img)[1].tofile(file_path)