Hi, first a disclaimer, i have almost zero knowledge in python, just getting code snippets all around an adding to my project..
My goal is it to use the Pi Camera to capture a screenshot and check the red, green and blue value of a specific pixel.
This is part of the code i used:
from picamera import PiCamera
from io import BytesIO
from PIL import Image
camera = PiCamera()
camera.resolution=(1280,720)
stream =BytesIO()
stream.seek(0)
camera.capture (stream,'jpeg')
im=Image.open (stream)
r,g,b=im.getpixel((x,y))
I'm using this in a Pi Zero W and is really slow.
I tried to skip the jpeg capture and go directly with the rgb format which , i think is the reason why this is so slow, using this system:
import picamera
import picamera.array
with picamera.PiCamera() as camera:
with picamera.array.PiRGBArray(camera) as output:
camera.capture(output, 'rgb')
print('Captured %dx%d image' % (
output.array.shape[1], output.array.shape[0]))
but i have no idea how to get the rgb values from output PiRGBArray
Thanks
Sorry for the bad english..
Re: Picamera capture and get single pixel r,g,b values
Please use code tags to format code.
for your problem, add the line:
with the same indentation as previouse print.
See the result is a 3 number tuple? these are the rgb values of pixel at line 101 column 101(*) in the captured image.
So the output array is three dimensional:
shape[0] = 480 (lines)
shape[1] = 720 (columns)
shape[2] = 3 (r,g,b values)
(*) an array's first index is 0
for your problem, add the line:
Code: Select all
print("pixel at 100x100", output.array[100,100])
See the result is a 3 number tuple? these are the rgb values of pixel at line 101 column 101(*) in the captured image.
So the output array is three dimensional:
shape[0] = 480 (lines)
shape[1] = 720 (columns)
shape[2] = 3 (r,g,b values)
Code: Select all
red_pixel_at_line_50_column_200 = output.array[49,199,0]
Re: Picamera capture and get single pixel r,g,b values
Thank you for the answer