raspberrypi / picamera2

New libcamera based python library
BSD 2-Clause "Simplified" License
891 stars 188 forks source link

Can't pass sensor argument when creating configuration #974

Closed ClassyCat1 closed 8 months ago

ClassyCat1 commented 8 months ago

I'm trying to select a sensor for capture, but for some reason I get: TypeError: create_preview_configuration() got an unexpected keyword argument 'sensor'

To Reproduce

I was following the Picamera2 manual, but that just lists to use the 'sensor' argument to specify which sensor to use. Here's my code:

from picamera2 import Picamera2, Preview

picam2 = Picamera2()
mode = picam2.sensor_modes[3]
config = picam2.create_preview_configuration(sensor={'output_size': mode['size'], 'bit_depth': mode['bit_depth']})
picam2.configure(config)
picam2.start()
picam2.capture_file("test.jpg")

Hardware : Using a raspberry Pi Zero WH and a Pi Camera V2

davidplowman commented 8 months ago

Unfortunately the Bookworm release is not yet being recommended for Pi Zero, so I assume you're still running the Bullseye release? The code you have will not run on Bullseye as that's no longer getting updates (it's now being regarded as "legacy").

I'm not quite sure what the best solution is there. Perhaps we should be hosting legacy versions of the manual? The plan is that Bookworm will be recommended for older Pis in due course, at which point you could switch and this will all be unnecessary. Alternatively, you could try the Bookworm 32-bit Lite OS and that would probably work. Sorry this is all a bit of a hassle at the moment.

As regards your example, you need to do this the "legacy" way (which actually still works on Bookworm too):

from picamera2 import Picamera2, Preview

picam2 = Picamera2()
mode = picam2.sensor_modes[3]
config = picam2.create_preview_configuration(raw=mode)
picam2.configure(config)
picam2.start()
picam2.capture_file("test.jpg")

should work, I think.

ClassyCat1 commented 8 months ago

Yes, that works! Thanks for the quick reply! I think a mention of the legacy way of doing it would be nice, as I wasn't sure if I was doing something wrong or if it was something with the code.

davidplowman commented 8 months ago

Great! I'll make a mental note to go and put something in the documentation for "legacy" systems, good idea.