George_P
Posts: 10
Joined: Sun Jun 16, 2013 12:11 am

PiCamera Raw RGB data / camera focus

Sat Oct 10, 2015 11:57 am

Hello,
We would very much appreciate if you could assist with two PiCamera problems we have.

A. We have been trying to get and further process the raw RGB data of captured images. To test this we run this script and see what values we get:

from picamera.array import PiRGBArray
from picamera import PiCamera
import time

camera = PiCamera()
camera.resolution = (640,480)
rc = PiRGBArray(camera)

time.sleep(0.5)

camera.capture(rc, format="RGB")

print rc.array.shape[0] # get one array dimension
print rc.array([0,0,0]) #??? value of the corner pixel RED component ???

raw_input("\n\n Press ENTER to exit")


Unfortunately there is no output as the program seems to become lost in the CAPTURE method.
There are no errors whatsoever when interpreting these lines, though we are not sure about the array syntax - is it the same as in NumPi arrays?
What are we doing wrong?
Are there any further documents with more details about the classes, methods and attributes of the PiCamera modules? I have seen the PiCamera Doc (release 1.10)...

B. The Picamera does not focus on short distances. We need to focus to distances no more than 7-10cm. We have read in other sites about turning the lens holder counterclockwise, but none of the methods suggested (thin pliers, rubber block, etc) worked so far for us, and we are afraid to force it any more as the whole camera assembly seems quite flimsy...

We have been trying to use the Pi and the camera as part of a system that detects impurities in a natural product - it would be great if we can get the Pi to do this job!

Best regards

User avatar
jbeale
Posts: 3688
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: PiCamera Raw RGB data / camera focus

Sun Oct 11, 2015 12:51 pm

You can add a close up lens. Cheap reading glasses could work, for example. Put the camera right up agaist the glasses. For 10 cm you need pretty strong lenses though, like a magnifying loupe.

Assuming you camera works at all (did you start testing with raspistill ?) The provided examples from the picamera docs should work.

George_P
Posts: 10
Joined: Sun Jun 16, 2013 12:11 am

Re: PiCamera Raw RGB data / camera focus

Sun Oct 11, 2015 9:50 pm

Many thanks for that...
I 'll try my glasses!!
As far as the RGB data for each pixel is concerned, is R at index 0, G at 1 and B at 2, or the other way round at the output array?

Best regards

User avatar
jbeale
Posts: 3688
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

Re: PiCamera Raw RGB data / camera focus

Mon Oct 12, 2015 4:06 am

For things like R,G,B index alignment, I don't normally trust the docs even if I can find them. There's too many places an index might get reversed; I just put a color chart up and figure it out from the output that I get. If you don't have a chart, for this kind of simple test you can even just print out something like
http://www.bealecorner.com/trv900/respa ... -chart.png or even just display it on the screen, if your camera is defocused enough so the screen pixels blur into a continuous color. (A digital camera in sharp focus on a LCD monitor tends to produce all kinds of moire patterns and color aliasing.)

George_P
Posts: 10
Joined: Sun Jun 16, 2013 12:11 am

Re: PiCamera Raw RGB data / camera focus

Mon Oct 12, 2015 9:32 pm

Thanks again!!!
This is exactly what I am doing.. looking at the output I get.
Fortunately our product is yellow(ish) on white background, and the impurities range from brown to black (the majority at least), so even if the image is a little out of focus, they can get detected...

Return to “Camera board”