Xelhas
Posts: 6
Joined: Wed Nov 21, 2018 1:11 am

Picamera get stuck when i use the command camera.close()

Wed Nov 21, 2018 1:19 am

Hi!
I'm having some problems executing python scripts with the closing cam command. When i use raspistill everything its okay, but when I execute a python script containing these command, the cam stucks and didnt close (also when I execute scripts and the closing order in separate way?
Someone could have an idea what i'm doing wrong?

Thanks (and sorry if i'm having mistakes with english, hope you understand the issue)

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Picamera get stuck when i use the command camera.close()

Wed Nov 21, 2018 8:40 am

Are you using Python with the picamera module?

Post a (minimal) script that shows the problem.
Use code tags when posting it (viewtopic.php?f=32&t=84477)

Xelhas
Posts: 6
Joined: Wed Nov 21, 2018 1:11 am

Re: Picamera get stuck when i use the command camera.close()

Mon Nov 26, 2018 11:24 pm

Here it is (sorry again, i thougth these things wouldn't be too fast :o )

Code: Select all

from picamera import PiCamera
from time import sleep
from fractions import Fraction
camera = PiCamera()
	camera.sensor_mode = 3 
	camera.resolution = (2592, 1944)
	camera.iso = 800 
	camera.shutter_speed = 6000000
	camera.framerate = Fraction(1,6) 
	sleep(30)
	camera.exposure_mode = 'off'
   	camera.capture('dark.jpg')
   	camera.close() 
It seems that python is not closing after executing the order
And I also tried to add an exit at the end of the script with sys.exit() but it doesnt work.

Thanks another time

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 9069
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Picamera get stuck when i use the command camera.close()

Tue Nov 27, 2018 12:06 pm

Test it without setting the long exposure time or sensor_mode. Everything takes a fair while with long exposures.

If you read the docs, then all examples will start with enabling preview, yet you haven't. I fail to see why you are therefore inserting the 30 second delay as I don't think it will do anything other than just wait doing nothing.

Actually it looks like things aren't being cleaned up tidily. When on 6 second exposures things take a long time, and it looks like some things may be timing out. I suspect that some ports aren't being disabled cleanly before ditching the component.
Inserting a 6 second delay seems to be vaguely reliable to ensure everything is idle.

Code: Select all

from picamera import PiCamera
from time import sleep
from fractions import Fraction
camera = PiCamera()
camera.sensor_mode = 3
camera.shutter_speed = 600000
camera.framerate = Fraction(1,6)
camera.resolution = (2592, 1944)
camera.iso = 800 
camera.start_preview()
sleep(30)
camera.exposure_mode = 'off'
camera.capture('dark.jpg')
camera.stop_preview()
sleep(6)
camera.close() 
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Xelhas
Posts: 6
Joined: Wed Nov 21, 2018 1:11 am

Re: Picamera get stuck when i use the command camera.close()

Thu Nov 29, 2018 12:01 am

Thank you, so much! It works :lol:

Return to “Camera board”