1
0

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.

Google Colabで画像を表示する

Posted at

①OpenCVをimportします。

!apt-get -qq install -y libsm6 libxext6 && pip install -q -U opencv-python

②画像をアップロードします。

from google.colab import files
uploaded = files.upload()

実行するとアップロードできるようになります。

③画像処理して表示します。(今回は二値化)

#-*- coding:utf-8 -*-
import cv2
import numpy as np
import matplotlib.pyplot as plt

# 入力画像を読み込み
img = cv2.imread("20190404 002.JPG")

# グレースケール変換
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# 二値化
retval, img_binary = cv2.threshold(img_gray, 180, 255, cv2.THRESH_BINARY)

# 結果を出力
plt.imshow(img_binary)

おわり!

1
0
2

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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?