问题:Glib-Gobject-warning **:无法注册现有类型“GDKDisplayManager”

Mar*_*ina 2 python gtk opencv pyqt raspberry-pi

我已经为我的树莓派设计了一个带有 pyqt 和 opencv python 的接口,所以当我运行基本测试来打开相机时没有问题( cv2.imshow('test',frame) 这太基本了,只是为了检查我的相机正在工作)是的,相机打开成功,但是当我尝试在 pyqt5 上创建的界面中打开相机时出现问题,因为它启动了一些错误,但主要是 Glib-Gobject-Warning **: cannot register existing type 'GDKDisplayManager'

完整错误:

Glib-Gobject-Warning **: cannot register existing type 'GDKDisplayManager'
Glib-critical **: g_once_init_leave: assertion 'result != 0 ' failed
Glib-Gobject-CRITICAL **:g_object_new: assertion 'G_TyPE_IS_OBJECT(Object_type)'fail
Glib-GObject-WARNING **: invalid (null) pointer instance
Glib-GObject-CRTICAL **: g_signal_connect_data: assertion 'G_TYPE_CHECK_INSTANCE(instance)'failed
Glib_GObject-WARNING **: cannot register existing type 'GdkDisplay'
Glib-critical **: g_once_init_leave: assertion 'result != 0 ' failed
Glib-Gobject-CRITICAL **: g_type_register_static: assertion 'parent_Type > 0'failed
Glib-critical **: g_once_init_leave: assertion 'result != 0 ' failed
Glib-Gobject-CRITICAL **:g_object_new: assertion 'G_TyPE_IS_OBJECT(Object_type)'failed
Run Code Online (Sandbox Code Playgroud)

这是打开相机的功能

def OpenCamera(self):
    self.setup_CameraSettings()       
    cap = cv2.VideoCapture(self.CameraSource) # video capture source camera (Here webcam of laptop) 
    cap.set(3, self.Resolution_x) # set the resolution
    cap.set(4, self.Resolution_y)
    cap.set(cv2.CAP_PROP_AUTOFOCUS, 0) # turn the autofocus off
    focus = self.Focus  # min: 0, max: 255, increment:5
    cap.set(cv2.CAP_PROP_FOCUS, focus)

    ret,frame = cap.read() # return a single frame in variable `frame`

    if ret== True:            
        cv2.imshow('Settings Test',frame)
        cv2.waitKey(0)
        cv2.destroyAllWindows() 
    else:
        self.popUp_Message('Camera Unplugged')
Run Code Online (Sandbox Code Playgroud)

这段代码在我的电脑上成功运行,所以问题不在函数中,我认为与我的树莓派上的 PyQt 有关

小智 9

[问题解决了]

我正在使用 PyQt5 开发 GUI。

运行此代码后我收到错误消息:

(python3:2306):GLib-GObject-WARNING **:10:3​​8:58.937:无法注册现有类型'GdkDisplayManager'(python3:2306):GLib-CRITICAL **:10:3​​8:58.938:g_once_init_leave:断言'结果!= 0'失败(python3:2306):GLib-GObject-CRITICAL **:10:3​​8:58.939:g_object_new_with_properties:断言'G_TYPE_IS_OBJECT(object_type)'失败

def SelectROI(self):

    #cv2.imshow("Select Region of Interest", self.browsed_img4)
    ImageToCrop = self.tmp_4.copy()
    

    r = cv2.selectROI(ImageToCrop)
     # Crop image

    imCrop = ImageToCrop[int(r[1]):int(r[1]+r[3]), int(r[0]):int(r[0]+r[2])]
Run Code Online (Sandbox Code Playgroud)

当您使用不同的 gtk 版本时会出现问题...对于我的情况,我在 QT 配置中使用 gtk2,但在我的机器中我使用 gtk3。

[解决方案]

编辑 qt5ct.conf 文件

sudo nano /etc/xdg/qt5ct/qt5ct.conf
# replace style=gtk2 with style=gtk3
ctrl+x y ENTER
Run Code Online (Sandbox Code Playgroud)