LoginSignup
8
10

More than 5 years have passed since last update.

Python3.6 opencv3.2 画像いじり①画像読み込み-表示-保存

Last updated at Posted at 2017-04-14

まえがき

画像をいじってみる。
OpenCVの導入はご自身でどうぞ
おなじみのlenaさんの画像を使います。

実行するコードと画像が別の場所にあるとして、
一度image_pathに画像のディレクトリのパスを指定します。

動作確認環境は以下の通り
- Python 3.6
- OpenCV 3.2

本題

何はともあれ画像出力

read_and_show.py
import cv2

#画像読み取り
image_path = "lenaさんの画像を格納してるディレクトリのパス" #例えば "C:\\Users\\admin\\Pictures\\"
image = cv2.imread(image_path+"lena.jpg")  #画像読み取り imread(filename)

#画像表示
cv2.imshow("image",image) #画像出力 imshow(window_name, matrix)
cv2.waitKey()             #キー入力待ち waitKey(delay=0)
cv2.destroyAllWindows()   #ウィンドウを消す destroyAllWindows()

そして保存

read_and_show_and_save.py
import cv2

#画像読み取り
image_path = "lenaさんの画像を格納してるディレクトリのパス" #例えば "C:\\Users\\admin\\Pictures\\"
image = cv2.imread(image_path+"lena.jpg")  #画像読み取り imread(filename)

#画像表示
cv2.imshow("image",image) #画像出力 imshow(window_name, image)
cv2.waitKey()             #キー入力待ち waitKey(delay=0)
cv2.destroyAllWindows()   #ウィンドウを消す destroyAllWindows()

#画像保存
cv2.imwrite(image_path+"result.jpg",image) #画像保存 imwrite(filename, image)
8
10
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
8
10