[PYTHON] I got an error when saving with OpenCV

Introduction

It is a learning memo.

a problem occured

When I was just starting to use OpenCV

#File reading
img = cv2.imread('./img.jpg')

###processing###

#File output
cv2.imwrite('./output', img)

Then, the following error occurred when outputting the file.

cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\imgcodecs\src\
loadsave.cpp:662: error: (-2:Unspecified error) could not find a writer for the
specified extension in function 'cv::imwrite_'

Solution

It seems that the cause was that I forgot to add the extension when outputting.

#File output
cv2.imwrite('./output.jpg', img)

With the extension, I was able to output safely.

By the way, the output seems to support the following formats.

jpg, jpeg, jpe, jp2, png, webp, bmp, pbm, pgm, ppm, 
pxm, pnm,  sr, ras, tiff, tif, exr, hdr, pic, dib 

in conclusion

It was a problem that made me laugh when I noticed it, but when it happened, I was quite worried. I would like to devote myself to eliminating particularly simple oversights.

Thank you for visiting.

Reference URL

http://blog.livedoor.jp/airyglyph0000/archives/3969423.html http://lang.sist.chukyo-u.ac.jp/classes/OpenCV/py_tutorials/py_gui/py_image_display/py_image_display.html

Recommended Posts

I got an error when saving with OpenCV
I got an error when using Tensorboard with Pytorch
I got an error when I put opencv in python3 with Raspberry Pi [Remedy]
When I get an error with PyInstaller
I get an error when I put opencv in pyautoGUI
I got a Value Error when using JUMAN ++ with PyKNP
I got an error when pip install pandas on Mac, so I dealt with it
I get an error with import pandas.
I got an error when I ran composer global require laravel / installer
When I get an error with Pylint in Atom on Windows
I get an error when trying to install maec 4.0.1.0 with pip
I got an error when I ran meteor add accounts-password and got hooked
I got an error when pip install tweepy on macOS Sierra, so I dealt with it
I got an error when trying to install Xgboost and its solution
I got an SSL related error with pip install, so I solved it
I get an error with all yum commands
Rollback processing when an error occurs with fabric
I got an error when trying to run Hello World in Go language
I got an error that Python couldn't read settings.ini
When OpenCV hconcat gives an error for some reason
I get an error when trying meinheld + WebSocket + mongodb
psql: I ran into an error with an invalid option --'''.
A memorandum when an error occurs with pip install
Error when playing with python
When I made CaboCha usable with python3, I got stuck (Windows 10)
I got an error in vim and zsh in Python 3.7 series
After installing CentOS8 with VirtualBox, an error occurs when restarting
What to do when an error occurs with import _ssl
When I installed python on macOS and used it, I got an error when I put an https connection
When coverage fails with _sqlite3 error
I tried trimming efficiently with OpenCV
I sent an SMS with Python
Draw an illustration with Python + OpenCV
I tried face recognition with OpenCV
I got an AttributeError when mocking the open method in python
[Beanstalk] What to do when an error occurs with import uuid
Solution when an error occurs when hiding the console screen with PyInstaller
I tried to make an image similarity function with Python + OpenCV
I got an SSL Error when I installed Anaconda in a new environment, so I solved it (Windows10, Anaconda3-2019.10)
I get an OS Error: [Errno 8] Exec format error when running a Flask application with a python command
I want to detect objects with OpenCV
I tried sending an SMS with Twilio
What I got into when using Tensorflow-gpu
Note when creating an environment with python
I tried sending an email with python.
I tried non-photorealistic rendering with Python + opencv
What to do if an error occurs when importing numpy with VScode
I got an unfamiliar error in Django: TypeError: resolve () got an unexpected keyword argument'strict'
A reminder of what I got stuck when starting Atcoder with python
[AWS] How to deal with WordPress "An error occurred when cropping an image."
Workaround if you get an error when trying to install PySide with pip
[Python] I want to know the variables in the function when an error occurs!
In the Chainer tutorial, I get an error when importing a package. (mock)
I want to send Gmail with Python, but I can't because of an error
An error occurs when trying to import scikit-learn after connecting to Oracle with SQLAlchemy
What I did when I got stuck in the time limit with lambda python
When I tried to connect with SSH, I got a warning about free space.
What to do if you get an error when installing python with pyenv
If you get a long error when tabbing an interactive shell with Anaconda
Linux Ubuntu16.04 I got a little scary error when I ran a command using sudo
Error when installing a module with Python pip