[OpenCV4.5.0]NumPyを使って赤色のみ抽出

import cv2
import numpy as np

img = cv2.imread("rose.jpg")

img[:, :, 0] = 0
img[:, :, 1] = 0

cv2.imwrite("result.png", img)

before

after

### HSVで赤っぽい部分の輪郭を表示

import cv2
import numpy as np

img = cv2.imread("rose.jpg")

hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV_FULL)
h = hsv[:, :, 0]
s = hsv[:, :, 1]
v = hsv[:, :, 2]

img2 = np.zeros(h.shape, dtype=np.uint8)
img2[(h > 200)  & (s > 100)] = 255

cv2.imwrite("result.png", img2)

ほう