Ipython cv2.imwrite() not saving image

前端 未结 3 1846
自闭症患者
自闭症患者 2021-02-05 17:16

I have written a code in python opencv. I am trying to write the processed image back to disk but the image is not getting saved and it is not showing any error(runtime and comp

3条回答
  •  自闭症患者
    2021-02-05 17:59

    As Jean suggested, the error is due to the \ being interpretted as an escape sequence. It is hence always safer to use os.path.join() as it is more cross platform and you need not worry about the escape sequence problem. For instance, in your case, you further need not worry about the first few arguments, as that is your home directory

    import os
    cv2.imwrite(os.path.join(os.path.expanduser('~'),'Desktop','tropical_image_sig5.bmp'), img2)
    

    os.path.expanduser('~') will directly return your home directory.

提交回复
热议问题