1

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()

I have no idea why it would fluctuate so crazily, I have uploaded an image to show what I mean, any help at all would very much be appreciated. Fluctuations of the maximum value of the Y array

Cheers,

David

  • I would assume this would be something to do with AGC adjusting the gains wildly (does the laser move in the camera's field of view? does it pulse at all?) but then I'm surprised that YUV is significantly different to grayscale derived presumably from RGB (although Y isn't really the same thing it typically serves as a decent enough substitute) – Dave Jones Aug 24 '15 at 13:09
  • The laser is stationary on a screen in the FOV of the camera module. It pulses slightly, but not nearly enough to account for the random movement seen above. Could it be something to do with the way picamera accesses frame information? – Kingdavidek Aug 26 '15 at 15:01
  • Unlikely - picamera just gets sent buffers of data by the camera and in the case of the yuv and rgb classes it just dumps them straight into numpy arrays (with yuv there is an extra step to double the dims of the UV planes which are quarter res as the camera uses YUV420 but that doesn't affect the Y plane which you're looking at) – Dave Jones Aug 26 '15 at 15:09
  • You could eliminate AGC as a culprit by using exposure mode "off" but give the camera some time to settle on reasonable gains first - after setting res and frame rate wait a couple of seconds, set the exposure mode and then give the analysis a try – Dave Jones Aug 26 '15 at 15:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.