import cv2 import numpy as np from IPython.display import Image, display def imshow(img): """ndarray 配列をインラインで Notebook 上に表示する。 """ ret, encoded = cv2.imencode(".jpg", img) display(Image(encoded)) def get_contours(img): # HSV 色空間に変換する。 hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) # 2値化する。 bin_img = cv2.inRange(hsv, (0, 0, 0), (255, 200, 255)) # 輪郭を滑らかにする。 bin_img = cv2.medianBlur(bin_img, 5) imshow(