HOME/Articles/

pil example picameriapillowmean (snippet)

Article Outline

Python pil example 'picameriapillowmean'

Modules used in program:

  • import picamera
  • import time
  • import io

python picameriapillowmean

Python pil example: picameriapillowmean

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