Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect a full black color image in OpenCV Python?

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?

like image 507
Hari Avatar asked Dec 31 '16 07:12

Hari


1 Answers

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).

like image 107
ebeneditos Avatar answered Sep 17 '22 15:09

ebeneditos