當文件路徑具有特殊字符(例如「é」)時,我無法保存圖像。由於文件路徑中的特殊字符,OpenCv imwrite不起作用
下面是從Python 3的外殼測試:
>>> cv2.imwrite('gel/test.jpg', frame)
True
>>> cv2.imwrite('gel/ééé/test.jpg', frame)
False
>>> cv2.imwrite('gel/eee/test.jpg', frame)
True
任何想法怎麼辦呢?
謝謝!
編輯:
不幸的是,@ PM2Ring和@DamianLattenero提出的所有建議似乎不工作:(
所以,我用的是@ cdarke的解決方案,這是我的最終代碼:
destination = 'gel/ééé/'
gel = 'test.jpg'
script_path = os.getcwd()
os.chdir(destination)
cv2.imwrite(gel, frame)
os.chdir(script_path)
哪個操作系統?你試過'cv2.imwrite('gel /ééé/ test.jpg'.encode(),frame)'? –
Windows 10(使用Python 3.6.1) 我試過了,它仍然沒有起作用... 'TypeError:壞的參數類型的內置操作',當我打印時:'b'gel/\ xc3 \ xa9 \ xc3 \ xa9 \ xc3 \ xa9/test.jpg'' – TeeVy
由於非ASCII字符在目錄名中,因此您可以使用'os.chdir('gel /ééé')',然後使用'cv2。 imwrite('test.jpg',frame)'?它的討厭和醜陋,但應該工作。 – cdarke