ProgrammNoob
ProgrammNoob

Reputation: 1

Issues Capturing Frames with OpenCV on CM4 + OV5647

I’m encountering issues while transitioning from a Raspberry Pi 4 + OV5647 camera to a Compute Module 4 (CM4) with eMMC + Waveshare Nano Base Board B + OV5647, running 32-bit Raspberry Pi OS Bullseye Lite .

To enable the camera on the CM4, I installed the CSI device tree blob from the Raspberry Pi Foundation: https://datasheets.raspberrypi.com/cmio/dt-blob-disp1-cam1.dts

After setup, the camera is detected and listed successfully:

libcamera-hello --list-cameras

Output:

0 : ov5647 [2592x1944] (/base/soc/i2c0mux/i2c@0/ov5647@36)
    Modes: 'SGBRG10_CSI2P' : 640x480 [58.92 fps - (16, 0)/2560x1920 crop]
                             1296x972 [43.25 fps - (0, 0)/2592x1944 crop]
                             1920x1080 [30.62 fps - (348, 434)/1928x1080 crop]
                             2592x1944 [15.63 fps - (0, 0)/2592x1944 crop]

To achieve this, I modified /boot/config.txt dtoverlay=ov5647,cam0 (This step was not required on the Raspberry Pi 4, but was necessary for the CM4.)

The Problem I have an OpenCV script that successfully grabs frames on the Raspberry Pi 4, but fails on the CM4.

Core Issue:

On the CM4, the script fails with Failed to grab frame, the same script works fine on the Raspberry Pi 4.

Here’s the script snippet responsible for capturing frames:

class VideoStream(object):
def __init__(self, path, queueSize=3):
    self.stream = cv2.VideoCapture(path, cv2.CAP_V4L)
    print("path: ", path)
    print("self.stream of cv2.VideoCapture(path) ", self.stream)
    print("Original frame size: " + str(int(self.stream.get(cv2.CAP_PROP_FRAME_WIDTH))) + "x" + str(int(self.stream.get(cv2.CAP_PROP_FRAME_HEIGHT))))
    self.stopped = False
    self.Q = Queue(maxsize=queueSize)

def start(self):
    # start a thread to read frames from the video stream
    t = Thread(target=self.update, args=())
    print("thread ",t)
    t.daemon = True
    t.start()
    return self

def update(self):
    try:
        while True:
            if self.stopped:
                return

            if not self.Q.full():
                (grabbed, frame) = self.stream.read()

                # if the `grabbed` boolean is `False`, then we have
                # reached the end of the video file
                if not grabbed:
                    print("Failed to grab frame")
                    self.stop()
                    return
                self.Q.put(frame)

                # Clean the queue to keep only the latest frame
                while self.Q.qsize() > 1:
                    self.Q.get()
    except Exception as e:
        print("Error in update: "+str(e))

def read(self):
    return self.Q.get()

I get the error:

Failed to grab frame

Questions:

  1. Is this a hardware-related issue (CM4 + Waveshare Nano Board B)?
  2. Is this a software configuration issue?
  3. If so, what additional steps should I take to get OpenCV working with the camera on the CM4?

Upvotes: 0

Views: 40

Answers (0)

Related Questions