手动选择感兴趣的区域,获取坐标
image_path = 'result2.jpg'
img_result1 = cv2.imread(image_path)
x1,y1,w1,h1 = cv2.selectROI(img_result1)
print(x1, y1, w1, h1)
cv2.destroyAllWindows()
对感兴趣的区域进行滤波处理
双边滤波处理
def do_shuangbian_img(x,y,w,h,img,d,sigmaColor,sigmaSpace):
roi = img[y:y+h,x:x+w]
roi = cv2.bilateralFilter(roi,d,sigmaColor,sigmaSpace)
img[y:y+h,x:x+w] = roi
cv2.imshow('result',roi)
cv2.imshow('result1',img)
cv2.imwrite('result2.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
do_shuangbian_img(x1,y1,w1,h1,img_result1,5,20,20)
中值滤波,高斯滤波,均值滤波处理
def do_medianBlur_img(x,y,w,h,img,ksize):
roi = img[y:y+h,x:x+w]
roi = cv2.medianBlur(roi,ksize)
img[y:y+h,x:x+w] = roi
cv2.imshow('result',roi)
cv2.imshow('result1',img)
cv2.imwrite('result2.jpg', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
do_medianBlur_img(x1,y1,w1,h1,img_result1,5)