def yuvPassShadowRemoval(src, shadowThreshold):
height, width = src.shape[:2]
imgYUV = cv2.cvtColor(src, cv2.COLOR_RGB2YUV)
yImg, uImg, vImg = cv2.split(imgYUV)
# for i in range(0, height):
# for j in range(0, width):
# yImg[i, j] = 0
yImg = np.zeros((height, width, 1), np.uint8)
imgYUV = cv2.merge([yImg, uImg, vImg])
rgbImg = cv2.cvtColor(imgYUV, cv2.COLOR_YUV2RGB)
rImg, gImg, bImg = cv2.split(rgbImg)
count = width * height
avg = np.sum(bImg)
avg /= count * 1.0
# for i in range(0, height):
# for j in range(0, width):
# if bImg[i, j] > ave:
# rImg[i, j] = 255
# gImg[i, j] = 255
# bImg[i, j] = 255
# else:
# rImg[i, j] = 0
# gImg[i, j] = 0
# bImg[i, j] = 0
if shadowThreshold is None:
avg = avg
else:
avg = shadowThreshold
np.where(bImg > avg, 255, 0)
_, threshold = cv2.threshold(bImg, avg, 255, cv2.THRESH_BINARY)
output = threshold
return output
评论列表
文章目录