gpt4 book ai didi

python - python opencv检测图像完全白

转载 作者:行者123 更新时间:2023-12-02 16:15:55 25 4
gpt4 key购买 nike

如何检测图像是否为白色。这意味着图像只有白色背景。
这是为黑色背景。
示例代码:

image = cv2.imread("image.jpg", 0)
if cv2.countNonZero(image) == 0:
print "Image is black"
return True
else:
print "Colored image"
return False

最佳答案

您可以在输入图像上执行bitwise_not操作并应用相同的逻辑(这只是一个技巧):

image = cv2.imread("image.jpg", 0)
image = cv2.bitwise_not(image)

if cv2.countNonZero(image) == 0:
print "Image is white"
return True
else:
print "Black region is there"
return False

关于python - python opencv检测图像完全白,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63129790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com