6
4

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-pythonで画像処理した画像をiTerm上で表示する

Last updated at Posted at 2018-02-07

概要

最近iTermを使い始めました。
画像をターミナル上で表示できるの便利ですよね。
それでipython上でopencvで画像処理してたんですけど、処理した画像をターミナル上で表示できたらいいなーっと思ったんでメモ

環境

  • macOS 10.12.6
  • iTerm2 3.1.5
  • Python 3.6.0
  • opencv-python 3.4.0.12
  • ipython 6.1.0

前提

imgcatを公式から落として、path通して実行できるようにしておきます。

実装

ドキュメントによれば、subprocess.runのinput引数にbyte sequenceを入れるとstdinに渡されるみたいなんで、imageのbytesをstdinでimgcatで渡してあげます

import cv2
import subprocess

def imgprint(image, format='.png'):
    _, buf = cv2.imencode(format, image)
    subprocess.run('imgcat', input=buf.tobytes())

スクリーンショット 2018-02-08 1.18.31.png

できました!

おわりに

地味に初投稿記事でした🤔(めっちゃ緊張した、、、)

とりあえず知識アウトプットする癖つけたい

参考

6
4
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
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?