I have been working with picamera python analysis class a bit lately. What I am using is here to get a YUV array, and then perform some simple analysis on it. When I try to isolate the Y page of the array and get the maximum value of the array, in other words, the brightest pixel on the image, it fluctuates wildly. Now I mean, the dynamic range jumps from around 40 to around 210 a few times in about 10 seconds. The image I am recording with the RPi camera module is a laser spot on a screen, heavily filtered. Using different code (just a grayscale image), the dynamic range of the brightest spot obtained is much more consistent, I mean a stdev of around 7. compared to stdev of pretty much the entire range using the YUV analysis class.
Now, I am sure the YUV class is successfully detecting the laser position because when I ask for the position of the brightest spot, the centroid coordinates are consistent with the laser position. The code I am using is here :
import picamera import picamera.array import numpy as np from numpy import unravel_index from time import time #Set resolution here Width = 640 Height = 480 ArrayY = 0 # Inherit from PiYUVAnalysis class MyAnalysisClass(picamera.array.PiYUVAnalysis): def analyse(self, array): #global ArrayY #global y ArrayY = array #print ArrayY.shape #print ArrayY.itemsize #y = ArrayY[0:Width, 0:Height, 0] y = ArrayY[:, :, 0] (cy, cx) = unravel_index(y.argmax(), y.shape) #get coordinates of brightest pixel #print cx #print cy #a = time() #print a print np.amax(y) #get value of brightest pixel with picamera.PiCamera() as camera: with picamera.array.PiYUVAnalysis(camera) as output: camera.resolution = (640, 480) #FOR SOME REASON, IF I SET THE RESOLUTION IN THE CORRECT ORDER, I GET IT WITH THE AXES INVERTED! camera.framerate = 30 output = MyAnalysisClass(camera) # so the output is not a file, but the MyAnalysisClass class, that was written above. camera.start_recording(output, format='yuv') camera.wait_recording(20) camera.stop_recording()