Python Picamera with GPIO Zero

Python Picamera with GPIO Zero

Picamera workshop given at Pi Towers Raspberry Jam, October 2016

A1995c9abe48450ce2f82d93ca0b863f?s=128

Ben Nuttall

October 15, 2016
Tweet

Transcript

  1. 2.

    Raspberry Pi camera module - 5Mpx / 8Mpx - Full

    HD - Photo & video - Command line - Python module - Infra-red camera
  2. 6.

    IDLE Python Shell >>> from picamera import PiCamera >>> from

    gpiozero import Button >>> camera = PiCamera() >>> button = Button(17) >>> button.when_pressed = camera.start_preview >>> button.when_released = camera.stop_preview
  3. 7.

    Open a new file • File > New File •

    File > Save • Save as camera.py
  4. 8.

    Take a selfie from picamera import PiCamera from time import

    sleep camera = PiCamera() camera.start_preview() sleep(3) camera.capture("/home/pi/image.jpg") camera.stop_preview() Save and run: Ctrl + S F5
  5. 9.

    Add GPIO Button code from picamera import PiCamera from gpiozero

    import Button from time import sleep camera = PiCamera() button = Button(17) camera.start_preview() button.wait_for_press() sleep(3) camera.capture("/home/pi/button.jpg") camera.stop_preview()
  6. 10.

    Add a loop camera.start_preview() for i in range(5): button.wait_for_press() sleep(3)

    camera.capture("/home/pi/button%s.jpg" % i) camera.stop_preview()
  7. 13.

    Picamera effects import random camera.start_preview() for i in range(5): button.wait_for_press()

    effect = random.choice(list(camera.IMAGE_EFFECTS)) camera.image_effect = effect camera.annotate_text = effect sleep(5) camera.capture("/home/pi/%s.jpg" % effect) camera.stop_preview() Try more effects: - negative - colorswap - sketch - emboss