Python OpenCV - Video Frame Image Depth

Hi there, I’m really struggling to find any Python example in the Docs or the tutorials of reading video frames at the native image depth. So far I have only managed to get 8-bit integer frames - I must be doing something very wrong.

Below is a brief example of what I’m trying to achieve, using a very small video of just 11-frames so that others can reproduce if needed.

cv2 is recognising the Float32 setting (cv2.CV_32F) and also the cv2.CAP_PROP_FORMAT, but it doesn’t seem to want to change the setting from the default.

import cv2
import numpy as np

movie_data="https://github.com/paul-goodall/python_opencv_framedepth/blob/main/test_movie.mov?raw=true"

# print some useful information about a numpy array:
def ndarray_info(nda):
    print("type\t: ", nda.dtype,"\nshape\t: ", nda.shape, "\nmin\t: ", nda.min(), "\nmax\t: ", nda.max(),"\n")

# Get the video frame:
vid_capture = cv2.VideoCapture(movie_data)

# Doesn't seem to watch to change the format:
vid_capture.set(cv2.CAP_PROP_FORMAT, cv2.CV_32F)
print("set? CAP_PROP_FORMAT = " + str(vid_capture.get(cv2.CAP_PROP_FORMAT)))
print("value CV_32F = " + str(cv2.CV_32F))
print("value CV_32FC1 = " + str(cv2.CV_32FC1))
vid_capture.set(cv2.CAP_PROP_FORMAT, 5.0)
print("set? CAP_PROP_FORMAT = " + str(vid_capture.get(cv2.CAP_PROP_FORMAT)))

if (vid_capture.isOpened() == False):
  print("Error opening the video file")
# Read fps and frame count
else:
    vid_fps = vid_capture.get(5)
    vid_frame_count = vid_capture.get(7)
    print('Found ' + movie_data + ' with ' + str(vid_frame_count) + ' frames.')
    while(vid_capture.isOpened()):
        # Try grab+retrieve:
        vid_capture.grab()
        ret1, img1 = vid_capture.retrieve(cv2.CV_32F)
        # Try read:
        ret2, img2 = vid_capture.read()
        if ret1 == True and ret2 == True:
                ndarray_info(img1)
                ndarray_info(img2)
                break

The frame is read as an 8-bit integer regardless of what I do, as the output shows:

set? CAP_PROP_FORMAT = 0.0
value CV_32F = 5
value CV_32FC1 = 5
set? CAP_PROP_FORMAT = 0.0
Found https://github.com/paul-goodall/python_opencv_framedepth/blob/main/test_movie.mov?raw=true with 11.0 frames.
type	:  uint8 
shape	:  (1080, 1920, 3) 
min	:  0 
max	:  255 

type	:  uint8 
shape	:  (1080, 1920, 3) 
min	:  0 
max	:  255 

Perhaps some of the experts can tell me what I’m doing wrong here?

Many thanks.
Goodsy

Hi,
You cannot change video format like this. It’s like file extension. If you change file extension .png in .jpg it does not change file data.
If you want to change file data you have to read all data and record it in the new format.
Now for video I don’t know if there is a codec using float for pixel