(process:43094): GLib-GObject-CRITICAL : 08:22:37.790: g_type_set_qdata: assertion ‘quark != 0’ failed

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:anas1155@192.168.1.168:554/Streaming/Channels/1/”)
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()    

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

Hey @haldun

It seems the error you’re encountering relates to library conflicts or configuration issues with GLib or OpenCV when accessing the RTSP stream. Here are some steps to help you resolve it:

1. Verify HailoRT Installation and Dependencies

Make sure the HailoRT drivers and libraries are installed correctly. Follow these steps based on the provided installation script:

  1. Update packages and install dependencies:

    sudo apt-get update
    sudo apt-get install -y build-essential cmake git wget linux-modules-extra-$(uname -r)
    
  2. Install appropriate headers:

    • ARM (e.g., Raspberry Pi):
      sudo apt install -y linux-modules-extra-$(uname -r)
      
  3. Verify Hailo PCI driver:
    Load the driver:

    sudo modprobe hailo_pci
    

    Confirm the device is detected:

    lspci | grep hailo
    

2. Fixing the GLib-GObject-CRITICAL Error

This issue often occurs due to conflicts in GStreamer or OpenCV backends. Try the following steps:

  1. Install GStreamer and OpenCV (headless):

    sudo apt install gstreamer1.0-tools gstreamer1.0-plugins-base gstreamer1.0-plugins-good
    pip install opencv-python-headless
    
  2. Use GStreamer backend with OpenCV:
    Modify the VideoCapture call:

    cap = cv2.VideoCapture("rtsp://admin:anas1155@192.168.1.168:554/Streaming/Channels/1/", cv2.CAP_GSTREAMER)
    

3. Code Adjustments and Debugging Tips

  1. Correct the if __name__ == "__main__" block:
    Replace:

    if name == “main”:
    

    With:

    if __name__ == "__main__":
    
  2. Test RTSP Stream:
    Verify stream accessibility using VLC:

    vlc "rtsp://admin:anas1155@192.168.1.168:554/Streaming/Channels/1/"
    
  3. Add Stream Reconnection Logic:
    Handle possible connection drops:

    while True:
        success, frame = cap.read()
        if not success:
            print("Failed to retrieve frame. Retrying...")
            cap.open("rtsp://admin:anas1155@192.168.1.168:554/Streaming/Channels/1/")
            continue
    
  4. Ensure Proper Use of Hailo Functions:
    Confirm that the frame passed to hailo.get_roi_from_buffer() is formatted correctly. If necessary, initialize the HailoRT environment as described in the HailoRT User Guide.


These steps should help you resolve the error. Let me know if you encounter further issues!

when i run this command
I did not see any result

  1. Verify Hailo PCI driver:
    Load the driver:
sudo modprobe hailo_pci

Confirm the device is detected:

lspci | grep hailo

(myenv) rasai@raspberrypi:~/kh $ sudo apt install -y linux-modules-extra-$(uname -r)

Reading package lists… Done

Building dependency tree… Done

Reading state information… Done

E: Unable to locate package linux-modules-extra-6.6.51+rpt-rpi-2712

E: Couldn’t find any package by glob ‘linux-modules-extra-6.6.51+rpt-rpi-2712’