18
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

OpenCV で保存する時にエラーが出た

Posted at

#はじめに
 学習メモです。

#問題発生
 OpenCVを使い始めたばかりの頃、

#ファイル読み込み
img = cv2.imread('./img.jpg')

###処理###

#ファイル出力
cv2.imwrite('./output', img)

 とすると、ファイル出力時に以下のエラーが出ました。

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_'

#解決
 出力時に拡張子を付け忘れていたのが原因だったようです。

#ファイル出力
cv2.imwrite('./output.jpg', img)

 と、拡張子を付けると無事出力できました。

 ちなみに、出力は以下の形式に対応しているようです。

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

#おわりに
 気づいてしまえば笑ってしまうような問題でしたが、発生した時はけっこう悩みました。
 特に簡単な見落としこそ無くせるように精進していきたいです。

 ご覧いただきありがとうございました。

#参考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

18
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
18
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?