0

I have two camera connected to RPi (1 USB camera and 1 RPi camera). I need to capture both images to do some processing on them right after image capture

I have this code:

file1 = 'imagecapture' + '_view1.png'
file2 = 'imagecapture'  + '_view2.png'
p1 = subprocess.Popen(
    "sudo raspistill -t 1500 -o {} -w 1920 -h 1080".format(file1), shell=True)

p2 = subprocess.Popen(
    "fswebcam -S 20 --resolution 1920x1080  --rotate -90 --device /dev/video1 {}".format(file2), shell=True)
p1.wait()
p2.wait()
time.sleep(0.2)
GPIO.cleanup()

The sleep I have added to make sure that image is captured and saved in the directory before I read it again and so some processing (I tested it and 2 seconds is sufficient).

This whole process takes 7-8 seconds. How can I make it even quicker? Is it possible to make it 3-4 seconds?

RPi Specs:

PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

RPi camera: rpi imx477

3
  • Sorry, I meant capture takes 1-2 seconds so total 3-4 seconds. Updated the question. I want to reduce the time to half or as low as possible.
    – Sulphur
    Commented Apr 11, 2022 at 18:43
  • WHY would you want to run a python script JUST to run 2 command line programs? Just run from a script - better run 2 which will probably use the multiple processors on the Pi4 to run simultaneously!
    – Milliways
    Commented Apr 12, 2022 at 2:20
  • @Milliways I have more things in the script, I only shared a snippet. The code I shared saves the images captured by Rpi before performing any processing on them. I 'need' to save the images somewhere before I do processing.
    – Sulphur
    Commented Apr 12, 2022 at 6:06

1 Answer 1

1

Opening the camera as a video stream.


Or

from picamera import PiCamera
from time import sleep

camera = PiCamera()
camera.rotation = 180
camera.resolution = (1024, 768)

camera.start_preview()
camera.capture(my_stream, 'jpeg')
sleep(5)
camera.stop_preview()

Also doing this in C or C++ which are compiled languages will be faster. Interrupted languages like python have to be re-interrupted each time.


https://pyimagesearch.com/2016/08/29/common-errors-using-the-raspberry-pi-camera-module/

# import the necessary packages
from picamera.array import PiRGBArray
from picamera import PiCamera
import time
import cv2
# initialize the camera and grab a reference to the raw camera capture
camera = PiCamera()
camera.resolution = (640, 480)
camera.framerate = 32
rawCapture = PiRGBArray(camera, size=(640, 480))
# allow the camera to warmup
time.sleep(0.1)
2
  • I dont need preview because I remotely connected to it. When you write sleep(5), does it mean it takes 5 seconds to store the capture?
    – Sulphur
    Commented Apr 11, 2022 at 21:10
  • The 5 seconds is the preview is active for 5 seconds before quitting. You can probably go with out the start and stop preview, you just won't get an on screen preview.
    – cybernard
    Commented Apr 12, 2022 at 1:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.