GLib-GObject-CRITICAL **: 14:16:35,807: g object ref: assertion 'G IS OBJECT (object)' failed

When I use the compiled version of cuda opencv to read RTSP video streams through multiple threads on Jetson AGX Orin, it is normal at the beginning, but after a period of time, the program will crash and report the error GLib Object CRITICAL * *: 14:16:35807: g object ref: assignment ‘G IS OBJECT (object)’ failed. How can I solve this problem? Here is my program and specific errors:

import cv2
import threading

def open_cam_rtsp(uri, width, height, latency):
    gst_str = ("rtspsrc location={} latency={} ! rtph264depay ! h264parse ! nvv4l2decoder ! "
               "nvvidconv ! video/x-raw, width=(int){}, height=(int){}, format=(string)BGRx ! "
               "videoconvert ! appsink sync=false" ).format(uri, latency, width, height)

    return cv2.VideoCapture(gst_str, cv2.CAP_GSTREAMER)

uri1 = 'rtsp://admin:a1111111@192.168.1.94:554/h264/ch1/main/av_stream'
uri2 = 'rtsp://admin:a1111111@192.168.1.84:554/h264/ch1/main/av_stream'

latency = 100
width1 = 1280
height1 = 720

width2 = 2560
height2 = 1440

def camera1_thread():
    cap1 = open_cam_rtsp(uri1, width1, height1, latency)
    while True:
        ret, frame = cap1.read()
        if ret:
            cv2.imshow('Camera 1', frame)
        if cv2.waitKey(1) == ord('q'):
            break
    cap1.release()
    cv2.destroyAllWindows()

def camera2_thread():
    cap2 = open_cam_rtsp(uri2, width2, height2, latency)
    while True:
        ret, frame = cap2.read()
        if ret:
            cv2.imshow('Camera 2', frame)
        if cv2.waitKey(1) == ord('q'):
            break
    cap2.release()
    cv2.destroyAllWindows()
if __name__ == '__main__':
    t1 = threading.Thread(target=camera1_thread)
    t2 = threading.Thread(target=camera2_thread)

    t1.start()
    t2.start()
 
    t1.join()
    t2.join()

Hi,
This looks to be constraint of OpenCV. A user has reported a similar issue in
Taking in two Gstreamer VideoCapture into OpenCV can only be done in a single thread

You may try the proposed solution.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.