1. 程式人生 > 其它 >cv2.imwrite(“file_path“, file_name)報錯!!684: error: (-2:Unspecified error) could not find a writer...

cv2.imwrite(“file_path“, file_name)報錯!!684: error: (-2:Unspecified error) could not find a writer...

·錯誤提示

684: error: (-2:Unspecified error) could not find a writer for the specified extension in function 'cv::imwrite_'

·錯誤的程式碼

cv2.imwrite("yuchuli/seg22", gray_img)

·錯誤原因

你要寫入檔案系統所使用的名字沒有後綴jpg!

·修改

cv2.imwrite("yuchuli/seg22.jpg", gray_img)

圖解

在這裡插入圖片描述

參考程式碼

程式碼除錯小技巧以及填坑 error: (-2) could not find a writer for the specified extension in function imwrite_