Roi = hailo.get_roi_from_buffer(frame)

hello
When I run the following code, I get this error. Can you help me solve this problem?

code is

import hailo
from PIL import Image
import cv2
if name == “main ”:
print(‘start AI’)
cap =cv2.VideoCapture(“rtsp://admin:[email protected]:554/…”)

while True:
success, frame = cap.read()
if not success:
break
frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)

try:
roi = hailo.get_roi_from_buffer(frame)
detections = roi.get_objects_typed(hailo.HAILO_DETECTION)
print('hailo while ',detections)
# Process detections…
except Exception as e:
print(f"Error occurred: {e}")
break

cap.release()

in this line roi = hailo.get_roi_from_buffer(frame)
I get this error :
rasai@raspberrypi:~/kh $ python test.py

(process:43094): GLib-GObject-CRITICAL : 08:22:37.790: g_type_set_qdata: assertion ‘quark != 0’ failed
[/quote]
the error comes from this line
roi = hailo.get_roi_from_buffer(frame)

Hey @inas ,

Welcome to the Hailo Community!

It looks like the GLib-GObject-CRITICAL error you’re encountering is likely due to a conflict between libraries, especially involving OpenCV, GStreamer, or the Hailo SDK. Let’s walk through some steps to help you resolve this:


1. Ensure Correct Environment Setup

First, make sure all necessary libraries are installed. Run the following commands to install the required packages:

sudo apt update
sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good
pip install opencv-python-headless

2. Use GStreamer as the Backend for VideoCapture

The error could be related to how OpenCV interacts with GStreamer. Try explicitly setting the GStreamer backend:

cap = cv2.VideoCapture("rtsp://admin:[email protected]:554/...", cv2.CAP_GSTREAMER)

This ensures OpenCV uses GStreamer properly and might resolve the conflict.


3. Correct the Syntax for the Main Block

There’s a small syntax issue in your code. The if block should look like this:

if __name__ == "__main__":
    print('start AI')

4. Ensure the Frame is Properly Formatted

The frame passed to hailo.get_roi_from_buffer() needs to have the correct format. Make sure it’s converted correctly:

frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
frame = frame.astype('uint8')  # Ensure correct data type if needed

5. Test the RTSP Stream Using VLC

To confirm that the RTSP stream is accessible, try opening it with VLC:

vlc "rtsp://admin:[email protected]:554/..."

If the stream doesn’t open, the issue might be with the RTSP link or camera settings.


6. Suppress GLib Warnings (Optional)

If the issue persists and the error is not critical, you can suppress the GLib warnings by setting the following environment variable:

export G_DEBUG="fatal-warnings"

7. Add Debugging for the Frame

To ensure the frame is valid before calling get_roi_from_buffer(), add a print statement to inspect it:

print(f"Frame shape: {frame.shape}, dtype: {frame.dtype}")
roi = hailo.get_roi_from_buffer(frame)

Let me know if these steps help or if you encounter any further issues!

Best Regards,
Omri