Ov2311-monochrome-uvc webcam RPI-4B save RAW image


How can I record RAW (8/10Bit) images with a set FPS (5,10) on a Pi-4B?
I’m using this camera module:

I’m quite new to all this and I have been trying to work with python/opencv/gstreamer etc. to write uncompressed (maybe even pickled numpy.arrays) for each image taken by the camera.
Is it possible to utilize one of the .cfg files from the USB-MIPI Camera shield .git repository?

If there are any codes/guides or how-tos available, I would greatly appreciate your help.

May you try the command below:

v4l2-ctl -d /dev/video0 --set-fmt-video=width=1600,height=1200,pixelformat='Y10 ' --stream-mmap 2 --stream-count=1 --stream-to=test.raw --verbose

I get the following output for your command.
The pixelformat 'Y10 ’ is invalid
VIDIOC_REQBUFS returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QUERYBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_QBUF returned 0 (Success)
VIDIOC_STREAMON returned 0 (Success)
cap dqbuf : 0 seq: 0 bytesused: 3840000 ts: 720.037772 delta: 720037.772 ms (ts-monotonic, ts-src-soe)

Please run the command to check a valid pixel format.

v4l2-ctl --list-formats-ext

Then run the command

v4l2-ctl -d /dev/video0 --set-fmt-video=width=1600,height=1200,pixelformat='**valid pixelformat**' --stream-mmap 2 --stream-count=1 --stream-to=test.raw --verbose

Hi, just a quick question you might now an answer to:

Q: How can I output each individual frame with an increment id from this v4l2-ctl command?

For example: After x amounts of seconds (given a default 5fps for YUYV on the OV2311 full resolution) I would like to see x*(fps) test.raw (test-0.raw, test-1.raw, test-2.raw,…) somewhere in a designated folder.

Also with potentially a pts/log or txt file with a timestamp for each frame taken and the metadata (gain,
exposure time, etc.) as well?


maybe need to write a shell script


FPS=5  # frames per second
WAIT_TIME=$((1 / FPS))  # wait time in microseconds
COUNT=0  # frame count

echo "Timestamp,File Name,Gain,Exposure Time" > log.csv  # create the CSV file and write the header

while true
    TIMESTAMP=$(date +%s.%N)
    v4l2-ctl --stream-mmap=3 --stream-count=1 --stream-to=$FILENAME --set-fmt-video=width=1920,height=1080,pixelformat=pgAA
    # GAIN=$(v4l2-ctl --get-ctrl=gain | awk '{print $NF}')  # get the gain value
    EXPOSURE=$(v4l2-ctl --get-ctrl=exposure | awk '{print $NF}')  # get the exposure time value
    echo "$TIMESTAMP,$FILENAME,$GAIN,$EXPOSURE" >> log.csv  # log the timestamp and metadata to the CSV file
    COUNT=$((COUNT + 1))
    sleep $WAIT_TIME

Thanks @Edward!
Great script!
I’ve only had to change the --get-ctrl commands according to v4l2-ctrl -d … --list-ctrls to make it work.

Only ‘issue’ that I’m having is that the ‘frame rate’ or better the writing speed and ‘output amount’ for the OV2311, for the mentioned ‘YUYV’ format to .raw, isn’t the default 5 fps.
But rather slower.

I had ‘better’ fps writing speeds through python (cv2), but there I had issues setting AND keeping the camera parameters to a specific setup (gain, exposure time,…).
@Edward you think it’s better to set camera settings in python via v4l2-ctrl, and then write .raw or .tiff/.png (or even pickle the images (i only need the pixel data)) via cv2, or go through the bash+v4l2-ctrl option and get the writing speed up (or even record .raw video)?



cv2 is fine. use python is better, code is better maintained.

what’s problem?

Sorry about the late reply.

doesn’t work with all the settings you get for ov2311 through
v4l2-ctl -d /dev/video0 -l

What I’m trying to do is set every parameter, for example the gain
subprocess.call(['v4l2-ctl -d /dev/video0 --set-ctrl gain={}'.format('**VALUE FOR GAIN'**), shell=True])
as well as all the others (I want to drive it to the lowest settings to make the image ‘dark’ but sharp)

but then only have the exposure_time_absolute be the only varying parameter for the camera.
Either through just setting it or writing my own routine - taking the max count from one frame and if np.max(frame) = 255 (given the default 8-bit; it would ideal to get somehow the 10-bit (1024) on the ov23110) adjust the exposure time with
subprocess.call(['v4l2-ctl -d /dev/video0 --set-ctrl exposure_time_absolute={}'.format('**SOME DELTA BETWEEN 1-5000'**), shell=True])

Ideally the auto_exposure could run with every ctl-value fixed EXCEPT for the exposure_time_absolute
subprocess.call(['v4l2-ctl -d /dev/video0 --set-ctrl auto_exposure=0', shell=True])

As of now even though I can ‘get’ all the information through those calls, I only get the default values.
If auto_exposure=3 is the default (Aperture Priority Mode), wouldn’t I still be able to ‘see’ the changes in gain, exposure_time_absolute, hue,… as the software on the ov2311 ‘does it’s job’?
I’m printing those in the cv2.VideoCapture while cam.isOpened():, but don’t see changes in values even though cv2.imshow clearly shows the camera adjustment to bright or dark sources.

I’d like to be able to log the ‘camera values for ever frame taken’(as well as additional metadata if available) through python for the OV2311 camera, for which I’m using cam = cv2.VideoCapture and ret, frame = cam.read() to get each frame