1 回答

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超6個(gè)贊
與我在這里提到的類似,您可以按照以下步驟進(jìn)行操作:
加載原始圖像并找到輪廓。
模糊原始圖像并將其保存在不同的變量中。
創(chuàng)建一個(gè)空的蒙版并在其上繪制檢測到的輪廓。
使用 np.where() 方法從要模糊值的蒙版(輪廓)中選擇像素,然后替換它。
import cv2
import numpy as np
image = cv2.imread('./asdf.jpg')
blurred_img = cv2.GaussianBlur(image, (21, 21), 0)
mask = np.zeros(image.shape, np.uint8)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray, 60, 255, cv2.THRESH_BINARY)[2]
contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(mask, contours, -1, (255,255,255),5)
output = np.where(mask==np.array([255, 255, 255]), blurred_img, image)
添加回答
舉報(bào)