I just recently got a Raspberry Pi HQ camera and wanted to operate it using a python script.
I initially tried to take full resolution pictures using the default gpu_mem=128, but the program crashed saying picamera.exc.PiCameraMMALError: unable to enable port vc.ril.camera.out:2: Out of memory
.
Setting the resolution to lower values worked and the pictures were taken without any issues. I then tried to change the gpu_mem to 256 MB as to give the camera enough space for full pictures.
When I rebooted the pi, however, and ran the script using full resolution, the camera hung and got stuck during the capture process. raspistill
however still works normally (as long as it's run before the script, which hangs and makes the camera inaccessible).
This is the relevant code:
def takeimg(params):
with picamera.PiCamera() as camera:
setup(camera, params)
sleep(2)
image = np.empty((params.camera.xres * params.camera.yres * 3,), dtype=np.uint8)
camera.capture(image, 'bgr')
image = image.reshape((params.camera.yres, params.camera.xres, 3))
return image
params
is a namedtuple containing some parameters used to set the camera.
I have tried different gpu_mem sizes but nothing above 128 MB seems to work consistently
Info:
- picamera module, version 1.13
- Rasperry Pi 3B+
- HQ Camera V1.0 2018
- Raspi OS Lite 32 bit Bullseye (latest version)
Any tips on how to take the pictures at full resolution? I'm really stuck at the moment
Edit:
I've done some testing and have narrowed down the issue by comparing these two scripts:
Script 1:
import picamera
import numpy as np
with picamera.PiCamera() as camera:
camera.resolution = (4032, 3040)
img = np.empty((4032*3040*3), dtype=np.uint8)
camera.capture(img, "bgr")
img = img.reshape((3040, 4032, 3))
Script 2:
import picamera
import numpy as np
with picamera.PiCamera() as cam:
cam.resolution = (4032, 3040)
cam.capture("picture.jpg")
While the second script runs without any issues, the first script gets stuck at the camera.capture('img', 'bgr')
, which means that (probably due to some gpu_mem issues) the camera isn't able to write to the numpy stream and remains stuck there instead.