I want to write code in python to print a text when the input image is perfectly black and no other colors are present in it. Which are the functions to be used?
Try this:
# open the file with opencv
image = cv2.imread("image.jpg", 0)
if cv2.countNonZero(image) == 0:
print "Image is black"
else:
print "Colored image"
You basically check if all pixel values are 0 (black).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With