Open carlyjb opened 7 months ago
Hi, and thanks for the question.
I think basically I have only bad news for you here. Two cameras show up because you've put them in your device tree, but unfortunately, to the Linux kernel these are the same device - that fact that there's some "magic" on the adpater board is completely unknown to it. There's no way you can have one device "left open" but use what you think is a second device but which to the kernel, is the same device - all those /dev/video<N>
nodes are the same in both cases, so they all have to be closed and re-opened.
libcamera-hello works as you describe because it does a complete shutdown when the process quits, just like quitting your Python process and starting over. So far as I know, there is no difference in this respect between using libcamera directly or Picamera2.
I think these are just the limits of adapter boards like this. You could get round this using a Pi with two physically distinct camera connectors, such as a Compute Module (or Pi 5). Beyond that, I guess if there's something particularly slow about closing one camera and opening another, then maybe there's something there that can be investigated. Do you have any further data on this?
Describe what it is that you want to accomplish I have (2) OV5647 cameras that are attached to an Arducam Multi Camera Adapter Module V2.2. I wish to preview from Camera 0 and capture an image and then switch to showing a preview and capture an image from Camera 1.
However, whenever I try to start Camera 1 after stopping Camera 0, I get a V4L2 device or resource is busy error.
ERROR V4L2 v4l2_videodevice.cpp:1047 /dev/video0[26:cap]: Unable to set format: Device or resource busy
Describe alternatives you've considered If I close() camera 0 instead of stopping, I am able to switch to camera 1 without issue. But that requires me to reinitialize/reallocate the Picamera2(0) the next time I want to switch back which is slow.
Additional context I am using a Raspi 4b running 64-bit Bullseye and a Waveshare 2.8 HDMI display. In my config.txt I am using
dtoverlay=camera-mux-4port,cam0-ov5647,cam1-ov5647
andcamera_auto_detect=0
to enable the multi camera adapter.libcamera-hello -t 0 --camera 0
andlibcamera-hello -t 0 --camera 1
both work successfully from the terminal.print(Picamera2.global_camera_info()) produces
[{'Model': 'ov5647', 'Location': 2, 'Rotation': 0, 'Id': '/base/soc/i2c0mux/i2c@1/pca@70/i2c@0/ov5647@36'}, {'Model': 'ov5647', 'Location': 2, 'Rotation': 0, 'Id': '/base/soc/i2c0mux/i2c@1/pca@70/i2c@1/ov5647@36'}]
This is a minimal code example that reproduces the error. It occurs even with just trying to capture images without displaying the preview.
How do I cleanly stop() camera 0 or force a reconfigure so that I can use camera 1 without deallocating camera 0 entirely?