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)

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="10 (buster)"

RPi camera: rpi imx477

  • 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


Opening the camera as a video stream.


from picamera import PiCamera
from time import sleep

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

camera.capture(my_stream, 'jpeg')

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.


# 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
  • 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.