Getting error - "writer could not be found" giving imshow, imwrite command opencv

I am new to opencv and python. I just installed opencv2.4.9 and enthought canopy-32bit. I am getting the error:

import cv2
image = cv2.imread('Lena.jpg')
cv2.imwrite('Mypic',image)

      

This is what I get:

c:\users\nam\appdata\local\temp\tmpokspbt.py in <module>()
      3 
      4 image = cv2.imread('Lena.jpg')
----> 5 cv2.imwrite('Mypic',image)

error: ..\..\..\..\opencv\modules\highgui\src\loadsave.cpp:275: error: (-2) could not find a writer for the specified extension in function cv::imwrite_

      

+3


source to share


2 answers


you need to provide the imwrite () extension so that it knows how to save (compress) it.



cv2.imwrite('Mypic.png',image)
# jpg,bmp,png,ppm,pgm,tiff supported 'out-of-the-box,
# webp,jp2 depending on if you compiled in the resp. 3rd party support
# no gif or tga.

      

+11


source


You need to make sure you have an image type inside the string you are passing to imwrite (). Dose imwrite () has no default method to save, so it is required within the name you give it. instead of: cv2.imwrite('Mypic',image)

you need to write:

cv2.imwrite('Mypic.The_format_you_want_to_save',image)

      



As an example:

cv2.imwrite('Mypic.jpg',image)

      

+1


source







All Articles