Raspberry Pi 5 with Global Shutter

I’m trying to use a Raspberry Pi 5 with the official Global Shutter Camera, but I keep getting the following error:

Error: gst-stream-error-quark: Internal data stream error. (1), ../src/gstreamer/gstlibcamerasrc.cpp(651): gst_libcamera_src_task_enter (): /GstPipeline:pipeline0/GstLibcameraSrc:source:
streaming stopped, reason not-negotiated (-4)
Shutting down... Hit Ctrl-C again to force quit.

I understand that I need to explicitly specify both the main (preview) resolution and the low-resolution (for inference) in order to avoid a format negotiation issue. For example, something like:

--lores-width 640 --lores-height 640 \
--width 1456 --height 1088

However, I also want to integrate this configuration into a custom detection.py file because I’m using a YOLO custom model with a custom detection script.

I’d appreciate any help or guidance on how to properly set the main/lores resolutions within my Python script (detection.py) so that the camera can run without triggering the not-negotiated error. Thank you!