图片亮度变化后,canny检测的结果也产生变化

当图片的亮度发生变化后, 其canny检测的结果也会发生变化。

import cv2
import numpy as np

img = cv2.imread('./lena.png')
img = cv2.resize(img, (400, 400))

def contrast_brightness_demo(image, c, b):            # 定义方法, 
    h, w, ch = image.shape
    blank = np.zeros([h, w, ch], image.dtype)         # 定义一张空白图像
    dst = cv2.addWeighted(image, c, blank, 1-c, b)     # 设定权重
    cv2.imshow("con-bri-demo", dst)
    lena2 = cv2.Canny(dst, 100, 200)
    cv2.imshow("dst", lena2)

# 阈值较大, 边缘不够精细
lena1 = cv2.Canny(img, 100, 200)
contrast_brightness_demo(img, 1.5, 2) 
cv2.imshow('img', img)
cv2.imshow('lena', lena1)

cv2.waitKey(0)
cv2.destroyAllWindows()

猜你喜欢

转载自blog.csdn.net/March_A/article/details/129741624