3

The raspistill -o image.jpg command successfully captures images. But when I try capturing from a really simple Python script, I get an error. The script is

from picamera import PiCamera

cam = PiCamera()
cam.capture('image.jpg')
cam.close()

The error is

Traceback (most recent call last):
  File "/home/pi/Documents/CamTest.py", line 6, in <module>
    camera.capture('image.jpg')
  File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1423, in capture
    'Timed out waiting for capture to end')
picamera.exc.PiCameraRuntimeError: Timed out waiting for capture to end

What am I missing here? Need help.

[OS: Linux raspberrypi 4.9.59-v7+ | picamera v1.13 | Raspberry Pi Camera Rev 2.1]

  • Are you sure there's not a bit more to your script? I'd expect that to fail with NameError given you're initializing cam but trying to execute a method on camera – Dave Jones Nov 13 '17 at 12:47
  • Sorry, my bad. Typing mistake. But, still doesn't solve the issue. – MAAI Nov 14 '17 at 11:12
  • After hours of digging and trial-and-error I have some insight about the issue. Using cam.('image.jpg', use_video_port=True) I'm able to acquire somewhat "grainy" looking image. This is because images taken via still port by raspistill undergoes a strong noise reduction algorithm i.e. appear as higher quality compared to the video port Refer to picamera.readthedocs.io/en/latest/fov.html#the-still-port. I think the error is related to Encoding as indicated by pycamera/camera.py line 1423 @DaveJones – MAAI Nov 15 '17 at 0:56
  • It might not be relevant but I'm running raspbian 4.9.41-v7+, the 2017-09-07 release on raspberrypi.org. My pi isn't on a network where it can get updates. I can't reproduce the error, the image is captured fine. Do you have a spare card to test the older version? – Craig Nov 15 '17 at 13:27
  • I could try this older version but where do I download it from? Seems the official site only provides the latest versions. And I'm guessing you are using the Desktop not the Lite one(?). @Craig – MAAI Nov 15 '17 at 14:08
1

I can't exactly reproduce your problem (i had the "Out of resources (other than memory)" error), but I still think your code lacks a crucial part : closing the camera after use.

So your code may work, but only one time : after that, the camera ressource will be locked, until reboot.

Adding a simple line may be enough for your minimal exemple :

from picamera import PiCamera
cam = PiCamera()
cam.capture('image.jpg')
cam.close()

For a real world code, you may want to use one of these syntax, that close camera even on unexpected error :

camera = PiCamera()
try:
    # do something with the camera
    pass
finally:
    camera.close()

or

with PiCamera() as camera:
    # do something with the camera
    pass

References taken from : https://picamera.readthedocs.io/en/release-1.13/api_camera.html

  • Well, Its not working either. Even if it was the case I should get at least one image. 'Timed out waiting for capture to end') picamera.exc.PiCameraRuntimeError: Timed out waiting for capture to end error exists as before. @Technico.top – MAAI Nov 15 '17 at 11:53
-1

This is the answer:

camera.capture('image.jpg', use_video_port=True)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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