關于python讀寫圖片遇到中文路徑的問題
- cv2.imread
- cv2.imwrite
cv2.imread
Python進行圖片處理,第一步就是讀取圖片,一般路徑都是英文名,但必不可免會遇到中文問題,
如下:
s=r'20210414_信號燈2658_0.jpg'
img_cv = cv2.imread(s) # 讀取資料
print(img_cv.shape)
# AttributeError: 'NoneType' object has no attribute 'shape'
解決方法使用imdecode:
soure=r'20210414_信號燈2658_0.jpg'
img = cv2.imdecode(np.fromfile(soure, dtype=np.uint8), -1)
print(img.shape)
#(20, 18, 3)
cv2.imwrite
寫入圖片遇到的問題就是,不報錯,但沒有圖片,
#source 是輸入路徑,dest是輸出路徑
img = cv.imdecode(np.fromfile(soure, dtype=np.uint8), -1)
# print(img)
cv.imwrite(dest, img)
dest為輸出路徑,圖片名也必須為英文名,否則雖然不報錯,但是不能成功寫入,
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/336330.html
標籤:其他
上一篇:筆記2:yolov5訓練自己的目標檢測模型_創建并劃分資料集
下一篇:Ubuntu下編譯opencv
