detect low contrast image opencv code example
Example 1: feature to determine image too dark opencv
blur = cv2.blur(image, (5, 5)) # With kernel size depending upon image size
if cv2.mean(blur) > 127: # The range for a pixel's value in grayscale is (0-255), 127 lies midway
return 'light' # (127 - 255) denotes light image
else:
return 'dark' # (0 - 127) denotes dark image
Example 2: python opencv check image read
import cv2
import os.path
while not os.path.isfile("myImage.jpg"):
#ignore if no such file is present.
pass
img = cv2.imread("myImage.jpg", 0)
cv2.imwrite("result.jpg", img)