Some times you can encounter serious issues using a raspberry pi camera with open-cv specially using cv2.VideoCapture()
.
I encountered a lot of them without finding and figured out a as "elegant" as possible workaround.
If you have libcamera-hello
working on your raspberry this can be a solution for you.
This project is using the libcamera-vid command to generate an image buffer of the camera and then read it using opencv.