Created
June 28, 2015 17:42
-
-
Save waveform80/22dea34379d5a7171ce4 to your computer and use it in GitHub Desktop.
A quick demo of using PiRGBAnalysis for (semi) rapid analysis of RGB data
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
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 | |
def analyse(self, a): | |
r = int(np.mean(a[..., 0])) | |
g = int(np.mean(a[..., 1])) | |
b = int(np.mean(a[..., 2])) | |
c = (r << 16) | (g << 8) | b | |
print('Average color: #%06x' % c) | |
self.frame_num += 1 | |
with picamera.PiCamera() as camera: | |
camera.resolution = (320, 240) | |
camera.framerate = 30 | |
output = MyAnalysis(camera) | |
camera.start_recording(output, 'rgb') | |
camera.wait_recording(10) | |
camera.stop_recording() | |
print('FPS: %.2f' % (output.frame_num / 10)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment