Created
December 10, 2017 21:43
-
-
Save KramKroc/ea2c4aebd1db6ebd676d2b7b970b2ff4 to your computer and use it in GitHub Desktop.
Using the Pillow module to calculate average brightness of an image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io | |
import time | |
import picamera | |
from PIL import Image | |
from PIL import ImageStat | |
stream = io.BytesIO() | |
with picamera.PiCamera() as camera: | |
camera.start_preview() | |
time.sleep(2) | |
camera.capture(stream, format='jpeg') | |
stream.seek(0) | |
image = Image.open(stream).convert('L') | |
stat = ImageStat.Stat(image) | |
print("Brighness of image: ", stat.mean[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment