Setting Resolution on the B020201.

I’m looking to use the B020201 on a Raspberry Pi in Python and Open CV.

I need the information (or sample code) to set the camera to 720p.

 

Thanks in advance.

Hello,

You can refer to this link https://www.e-consystems.com/blog/camera/how-to-access-cameras-using-opencv-with-python/

#To set the resolution

cap.set(cv2.cv.CV_CAP_PROP_FRAME_WIDTH, 1280)

cap.set(cv2.cv.CV_CAP_PROP_FRAME_HEIGHT, 720)

Thanks for the reply, unfortunately it doesn’t work.

I currently have a Raspberry Pi 4 running Python 3.8 and OpenCV 3.4.3. I have a Raspberry Pi camera and a B020201 attached via USB.

Below is the code I use to test the camera(s):


import cv2
import numpy as np

cam0 = cv2.VideoCapture(0)
cam0.set(cv2.CAP_PROP_FRAME_WIDTH, 1920)
cam0.set(cv2.CAP_PROP_FRAME_HEIGHT, 1080)

cam1 = cv2.VideoCapture(1)
cam1.set(cv2.CAP_PROP_FRAME_WIDTH, 1280)
cam1.set(cv2.CAP_PROP_FRAME_HEIGHT, 720)

while(True):
    ret, frame0 = cam0.read()
    ret1, frame1 = cam1.read()

    cv2.imshow('piCam', frame0)
    cv2.imshow('ArduCam', frame1)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cam0.release()
cam1.release()
cv2.destroyAllWindows()

The Pi camera sets to 1080p properly, the ArduCam stays at the default 640x480 instead of changing to 720p

The code you referenced above works with an earlier version of OpenCV (2.x I believe) and errors out with the version I am running.

Hello,

Sorry for my late reply.

Can you use “v4l2-ctl --list-formats-ext” to check which resolution your camera supports?

 

[email protected]:~ $ v4l2-ctl --list-formats-ext
ioctl: VIDIOC_ENUM_FMT
Type: Video Capture

Size: Discrete 1920x1080
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1280x720
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 320x240
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 1920x1080
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.033s (30.000 fps)
[1]: ‘YUYV’ (YUYV 4:2:2)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 320x240
Interval: Discrete 0.033s (30.000 fps)
Size: Discrete 640x480
Interval: Discrete 0.033s (30.000 fps)
Interval: Discrete 0.033s (30.000 fps)

Hello,

From the formats list, the camera support mjpeg and YUV formats. For the YUV, it just supports

640x480 and 320x240. Can you try to 320x240 to test? Maybe the default is YUV mode.

 

From the formats list, the camera support mjpeg and YUV formats. For the YUV, it just supports

640×480 and 320×240. Can you try to 320×240 to test? Maybe the default is YUV mode.


Confirmed. It seems to be in YUV mode. How do I switch it?

 

Hello,

Please try to use cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FOURCC, cv.CV_FOURCC(‘M’, ‘J’, ‘P’, ‘G’)) to choose mjpeg mode

With slight modifications (for OpenCV version) that worked perfectly, thank you.

I’m using 3.4.3 of OpenCV so my code was as follows:

rearCap.set(cv2.CAP_PROP_FOURCC, cv2.VideoWriter.fourcc(*"MJPG"))

Great to hear that!