import cv2 import numpy as np image_path = "pisu5.jpg" src = cv2.imread(image_path) def skin_detect(src): hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV) hsv_min = np.aray([0, 30, 60]) hsv_max = np.array([20, 150, 255]) mask = cv2.inRange(hsv, hsv_min, hsv_max) return mask def mosaic(src, ratio=0.1): small = cv2.resize(src, None, fx=ratio, fy=ratio, interpolation=cv2.INTER_NEAREST) return cv2.resize(small, src.shape[:2][::-1], interpolation=cv2.INTER_NEAREST) def mosaic_area(src, x, y, width, height, ratio=0.02): dst = src.copy() dst[y:y + height , x:x + width] = mosaic(dst[y:y + height, x:x + width], ratio) return dst for ?????? cv2.imwrite("pisu5_detect.jpg", ??????)
コード
画像から肌色を検出して検出域にモザイクをかけるプログラムを作っています。 しかし、モザイクをかけて画像を保存するところがいまいち分からないので教えていただきたいです。 あと、もし不足している文があったらご指摘願いたいです。 よろしくお願いします。 ??????のところがどのように書いたらいいのかわかりません。 ### 該当のソースコード import cv2 import numpy as np image_path = "pisu5.jpg" src = cv2.imread(image_path) def skin_detect(src): hsv = cv2.cvtColor(src, cv2.COLOR_BGR2HSV) hsv_min = np.aray([0, 30, 60]) hsv_max = np.array([20, 150, 255]) mask = cv2.inRange(hsv, hsv_min, hsv_max) return mask def mosaic(src, ratio=0.1): small = cv2.resize(src, None, fx=ratio, fy=ratio, interpolation=cv2.INTER_NEAREST) return cv2.resize(small, src.shape[:2][::-1], interpolation=cv2.INTER_NEAREST) def mosaic_area(src, x, y, width, height, ratio=0.02): dst = src.copy() dst[y:y + height , x:x + width] = mosaic(dst[y:y + height, x:x + width], ratio) return dst for ?????? cv2.imwrite("pisu5_detect.jpg", ??????) ### 試したこと ### 補足情報(FW/ツールのバージョンなど) ここにより詳細な情報を記載してください。