Skip to content

Instantly share code, notes, and snippets.

View waveform80's full-sized avatar

Dave Jones waveform80

View GitHub Profile
@waveform80
waveform80 / motion_215.py
Last active September 8, 2021 16:23
Motion detection with a circular buffer and file recording in picamera
#!/usr/bin/env python
import io
import time
import picamera
import picamera.array
import numpy as np
from PIL import Image, ImageDraw
@waveform80
waveform80 / rgb_colors.py
Created June 28, 2015 17:42
A quick demo of using PiRGBAnalysis for (semi) rapid analysis of RGB data
from __future__ import division
import picamera
import picamera.array
import numpy as np
class MyAnalysis(picamera.array.PiRGBAnalysis):
def __init__(self, camera):
super(MyAnalysis, self).__init__(camera)
self.frame_num = 0
@waveform80
waveform80 / color_detect.py
Last active October 1, 2016 12:55
A list of little demos for picademy - see https://github.com/waveform80/picamera_demos for updated versions
import picamera
import numpy as np
from picamera.array import PiRGBAnalysis
from picamera.color import Color
class MyColorAnalyzer(PiRGBAnalysis):
def __init__(self, camera):
super(MyColorAnalyzer, self).__init__(camera)
self.last_color = 'none'
from gpiozero import RyanteckRobot, Button
from signal import pause
robot = RyanteckRobot()
button_actions = {
Button(26): robot.forward,
Button(16): robot.left,
Button(21): robot.right,
Button(20): robot.backward,
from gpiozero import LED, MotionSensor, LightSensor
from signal import pause
pir = MotionSensor(21)
ldr = LightSensor(26)
light = LED(25)
def daytime():
pir.when_motion = None
pir.when_no_motion = None
light.off()
def nighttime():
import ctypes as ct
from signal import pause
import numpy as np
from picamera import mmal, PiRenderer
from picamera.exc import (
PiCameraRuntimeError,
PiCameraValueError,
mmal_check,
)
from gpiozero import TrafficLights
from time import sleep
from itertools import cycle, chain
from signal import pause
lights = TrafficLights(12, 16, 19, pwm=True)
def slow(gen):
for item in gen:
yield item
@waveform80
waveform80 / fiddle_gains.py
Created September 11, 2016 09:33
A little script for testing what happens when you fiddle with the Pi camera module's gains and shutter speed
from __future__ import (
unicode_literals,
absolute_import,
print_function,
division,
)
str = type('')
from picamera import PiCamera
import curses
@waveform80
waveform80 / cacachart.py
Last active September 28, 2016 08:36
ASCII art charts!
from __future__ import (
unicode_literals,
absolute_import,
print_function,
division,
)
from itertools import tee
from collections import deque
from time import sleep
@waveform80
waveform80 / delay.md
Last active October 13, 2016 14:24
Delay demo

Delay

The demo script (delay.py) produces a "delayed" preview, with recording facilities. The pot (connected to the MCP3008) is used to control the amount by which the preview is delayed (can vary between 0 and 60 seconds), whilst one button is used to toggle recording (GPIO22), and the other to terminate the script (GPIO17).

Recording is written to "output.h264" in the current directory. This file is wiped when the script starts, and all recording is written to it (i.e. stopping the recording, then starting it again continues the recording from where it left off).