Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Infra-red bird box

Infra-red bird box

Infra-red bird box activity for Scouts digital day

Ben Nuttall

April 13, 2018
Tweet

More Decks by Ben Nuttall

Other Decks in Programming

Transcript

  1. Infra-red bird box camera
    Raspberry Pi Foundation
    UK Charity 1129409

    View full-size slide

  2. Raspberry Pi camera module

    5Mpx / 8Mpx

    Full HD

    Photo & video

    Command line

    Python module

    Infra-red camera variant

    30fps @ 1080p
    60fps @ 720p
    90fps @ 480p

    View full-size slide

  3. Night vision camera

    5Mpx

    Light sensors (LDR)

    Infra-red LEDs

    Adjustable lens focus

    Compatible with official camera
    module

    View full-size slide

  4. Connect the camera

    View full-size slide

  5. Enable camera software

    View full-size slide

  6. Test the camera
    $ raspistill -k

    View full-size slide

  7. Open Thonny Python IDE

    View full-size slide

  8. Thonny Python IDE
    File editor – saved code
    Shell – testing code

    View full-size slide

  9. Python picamera
    from picamera import PiCamera
    from time import sleep
    camera = PiCamera()
    camera.start_preview(alpha=200)
    sleep(10)
    camera.stop_preview()

    View full-size slide

  10. Rotation
    from picamera import PiCamera
    from time import sleep
    camera = PiCamera()
    camera.rotation = 180
    camera.start_preview(alpha=200)
    sleep(10)
    camera.stop_preview()

    View full-size slide

  11. Still images
    from picamera import PiCamera
    from time import sleep
    camera = PiCamera()
    camera.start_preview(alpha=200)
    sleep(5)
    camera.capture('/home/pi/Desktop/image.jpg')
    camera.stop_preview()

    View full-size slide

  12. Text annotation
    from picamera import PiCamera
    from time import sleep
    camera = PiCamera()
    camera.start_preview(alpha=200)
    camera.annotate_text = "Hello world"
    sleep(5)
    camera.capture('/home/pi/Desktop/image.jpg')
    camera.stop_preview()

    View full-size slide

  13. Multiple capture
    from picamera import PiCamera
    from time import sleep
    camera = PiCamera()
    camera.start_preview(alpha=200)
    for i in range(5):
    sleep(5)
    camera.capture('/home/pi/Desktop/image{}.jpg'.format(i))
    camera.stop_preview()

    View full-size slide

  14. Video
    from picamera import PiCamera
    camera = PiCamera()
    camera.start_preview(alpha=200)
    camera.start_recording('/home/pi/video.h264')
    camera.wait_recording(10)
    camera.stop_recording()
    camera.stop_preview()

    View full-size slide

  15. Video playback
    $ omxplayer video.h264

    View full-size slide

  16. PIR Motion Sensor

    View full-size slide

  17. Motion sensor
    from picamera import PiCamera
    from gpiozero import MotionSensor
    camera = PiCamera()
    pir = MotionSensor(4)
    pir.when_motion = camera.start_preview
    pir.when_no_motion = camera.stop_preview

    View full-size slide

  18. Motion sensor photo trigger
    from picamera import PiCamera
    from gpiozero import MotionSensor
    from datetime import datetime
    def capture():
    timestamp = datetime.now().isoformat()
    camera.capture('/home/pi/{}.jpg'.format(timestamp))
    camera = PiCamera()
    pir = MotionSensor(4)
    pir.when_motion = capture

    View full-size slide

  19. Motion sensor video trigger
    from picamera import PiCamera
    from gpiozero import MotionSensor
    from datetime import datetime
    camera = PiCamera()
    pir = MotionSensor(4)
    while True:
    if pir.motion_detected:
    camera.start_preview(alpha=200)
    timestamp = datetime.now().isoformat()
    camera.start_recording('/home/pi/{}.h264'.format(timestamp))
    camera.wait_recording(10)
    camera.stop_recording()
    camera.stop_preview()

    View full-size slide

  20. Circular stream video
    from picamera import PiCamera, PiCameraCircularIO
    from gpiozero import MotionSensor
    camera = PiCamera()
    pir = MotionSensor(4)
    stream = PiCameraCircularIO(camera, seconds=20)
    camera.start_recording(stream, format='h264')
    try:
    while True:
    camera.wait_recording(1)
    if pir.motion_detected:
    camera.wait_recording(10)
    stream.copy_to('motion.h264')
    finally:
    camera.stop_recording()

    View full-size slide

  21. Infra-red bird box camera
    Raspberry Pi Foundation
    UK Charity 1129409

    View full-size slide