'RaspberyPI high quality camera with opencv on max resolution

I bought RPI high quality camera and trying to make it work it with opencv and python.

I'm using Raspbery PI4 with latest updates (sudo apt update && sudo apt full-upgrade)

Its max resolution is 4056x3040 but it won't works on opencv with resolution more than 2560x1680.

With raspistill it works normally even on 4056x3040

I tried next resolutions in opencv:

  • 2048x1536 works
  • 2048x1680 works
  • 2240x1680 works
  • 2560x1440 works
  • 2560x1680 and above not works

raspistill command (works):

raspistill -w 4056 -h 3040

Python example code to work with max resolution (not works):

import cv2 as cv2

cap = cv2.VideoCapture(0)
if not cap.isOpened():
    print("Cannot open camera")
    exit()

HIGH_VALUE = 10000

# (Of cause, I tried to set manually all resolutions in next two lines)
cap.set(cv2.CAP_PROP_FRAME_WIDTH, HIGH_VALUE)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, HIGH_VALUE)

width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))

print(f"Camera resolution: {width}x{height}") # prints 4056x3040

while True:
    ret, frame = cap.read()

    if not ret:
        # Here it exit if resolution is 2560x1680 and above
        print("Can't receive frame (stream end?). Exiting ...")
        break

    cv2.imshow('frame', frame)
    if cv2.waitKey(1) == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Thanks for any help.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source