2

I was trying to capture images using the Python picamera module and was always getting Timed out waiting for capture to end error (See this question).

Since the shell command raspistill works fine, I'm planning to use it within a Python script. So far, I've been unable to achieve that. My code is

from picamera import PiCamera
import subprocess

camera = PiCamera()
cmd = "raspstill -vf -o home/pi/Pictures/image_shell.jpeg"
subprocess.call(cmd, shell=True)

The LED on the camera turns on for a second or two then turns off - gives me an idea that the image is captured (is it though?). But the captured image is no where to be found.

What am I doing wrong? Any ideas?

3
  • 5
    try another slash before "home". Also, why do you import PiCamera and initialise it that way when not using that? Try to remove the camera = PiCamera() in case that borks something up (i.e. blocking the resource).
    – Ghanima
    Commented Nov 14, 2017 at 21:41
  • picamera import was from previous trials. You were right. That camera initialization was blocking the resources. Now that its working, It seems a bit slow 6.52 seconds to be exact. Is there any way to speed it up? I need my code to spend as little time as possible in capturing the image.
    – MAAI
    Commented Nov 14, 2017 at 22:23
  • Try to stick to the python interface, it will be faster, as the camera is initialized only once, at program boot. I hope my answer on the other thread.may help you to achieve this. Commented Nov 15, 2017 at 2:59

3 Answers 3

3

Try to remove the camera = PiCamera() that creates an instance of the PiCamera class and initialises the camera, thus likely blocking the resource.

I also think that there should be another slash before "home" in this line, assuming a traditional file system layout.

cmd = "raspstill -vf -o home/pi/Pictures/image_shell.jpeg"

As to speeding up the whole process of taking a image, consider these hints:

Dave Jones' (developer of picamera) comment on this question:

Have a look at my answer to a similar question - raspistill's use of the still port makes it necessarily slow. If you want to get it over 1fps you'll need to modify it (or preferably modify raspividyuv as it's probably closer to what you need)

points to this answer which addresses the issue.


If you intend to process the image in Python right after capturing you can also skip saving it to file and use a file-like object, such as an io-stream or a numpy array instead. See the last part of my answer here. You will, however, need to drop the call of an external process and do the whole capturing in Python itself (not that that would be a bad thing).

0

I think you should be putting to photo in /home/pi/Pictures/image_shell.jpeg

if you don't have the leading / it's not going to select the right path.

0

The coding shown previously keeps indicating "raspstill". It should be "raspistill" instead of raspstill.

2

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.