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 total (basically 1-2 seconds for image capture)?

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

Sulphur
  • 514
  • 6
  • 24
  • You didn't say how long each command takes when run on its own. Or how long it takes if you run them in parallel in the shell with `sudo raspistill ... & fswebcam ... & wait` – Mark Setchell Apr 11 '22 at 22:25
  • Sorry for the ignorance but if I use subprocess (as above) wont the commands run in parallel? Edit: Sorry I just saw your edit. I will update individual times – Sulphur Apr 11 '22 at 22:27
  • Also, you might try saving the output as JPEG as it is normally considerably faster than PNG. Also, you could see if it is any faster if saving to `/tmp`. – Mark Setchell Apr 11 '22 at 22:28
  • Please use [edit] to add info to your question, rather than comments, btw. – Mark Setchell Apr 11 '22 at 22:30

0 Answers0