kko123
Posts: 1
Joined: Wed Aug 29, 2018 4:36 pm

Working with camera

Thu Oct 18, 2018 3:15 am

How can I implement this logic:
I have external sensor conected to GPIO, i must see on display one frame from camera when sensor is active.
All new frames must raplace old frames. Frequency expected from the sensor is about 10 Hz.
Any idea?
Now i trying simply capture the frame and show it:

Code: Select all

import RPi.GPIO as GPIO
import time
import picamera
import picamera.array
from PIL import Image

pin=2 												# sensor pin
GPIO.setmode(GPIO.BCM)       
GPIO.setup(pin, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)

with picamera.PiCamera() as camera:
    with picamera.array.PiRGBArray(camera) as stream:
        camera.resolution = (1280, 720)
        camera.iso = 800
        camera.awb_mode = 'auto'
        camera.framerate = 30
        time.sleep(2)

        while True:
            camera.capture(stream, 'rgb', use_video_port=True)
            stream.seek(0)
            img = Image.fromarray(stream.array, 'RGB')
            img.show()
            GPIO.wait_for_edge(pin, GPIO.RISING)
But images open in new window every time. How i can show it in the same window?
Can i use preview for my target?

User avatar
paddyg
Posts: 2555
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: Working with camera

Thu Oct 18, 2018 8:34 pm

Using the standard features such as preview must be easier but I have captured picamera images as numpy arrays and displayed them using the gpu like this https://github.com/pi3d/pi3d_demos/blob ... imal_2d.py
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

Return to “Python”