The issue of GTK 2+ and 3+ during running opencv on AGX

Dear all,

when I was running the cv2 with JetPack v4.4 on AGX, I got this error.

Gtk-ERROR **: 12:02:01.858: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported

When I used this command:
pkg-config --libs gtk+-2.0or pkg-config --libs gtk+-3.0

Output :

Package gtk+-2.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-2.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-2.0' found

or

Package gtk+-3.0 was not found in the pkg-config search path.
Perhaps you should add the directory containing `gtk+-3.0.pc'
to the PKG_CONFIG_PATH environment variable
No package 'gtk+-3.0' found

I searched it. (Reference: pkg-config not finding gtk±3.0)

Command:

dpkg -l libgtk* | grep -e '^i' | grep -e 'libgtk-*[0-9]' 

Output:

zsh: no matches found: libgtk*

Hence, I installed these libraries.

sudo apt-get install libwebkit2gtk-4.0-dev  libgtk-3-dev libglib2.0-dev autogen autoconf libtool m4 automake pkg-config libtool intltool-debian

So I can find something…
Command:

pkg-config --libs gtk+-3.0

Outuput:

-lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0

But I still get the same error. Cannot fix it.

Someone suggested that we can downgrade the opencv version to fix it.
The JetPack v4.4 default opencv version is 4.1.1.
However, this opencv version can work on my pc (linux).
As I have another Jetson device (TX2) which was installed by 3.2.0 with JetPack v4.3 and it can work my script without any error.
So I wonder is it better to downgrade the opencv version on AGX device? or any other method to fix this bug?

Thank you.

Environment

TensorRT Version : 7.1 with Jetpack 4.4
GPU Type : (Jetson AGX Xavier)
Nvidia Driver Version : Jetpack 4.4
CUDA Version : 10.2
CUDNN Version : 8.0
Operating System + Version : Jetpack 4.4 (Costimized Ubuntu 18.04)
Python Version (if applicable) : 3.6
PyTorch Version (if applicable) : 1.5.0
cmake version : 3.13.0
opencv version : 4.1.1

Hi,

This looks like a compatibility issue to me.
Would you mind to share a simple reproducible source and the compile command with us first?

Thanks.

I have the same issue on my Xavier so I’ll jump in and post example code.

My error message is:

(gtk_test.py:6182): Gtk-ERROR **: 09:06:47.973: GTK+ 2.x symbols detected. Using GTK+ 2.x and GTK+ 3 in the same process is not supported
Trace/breakpoint trap (core dumped)

Example Code Follows:

import cv2
import time
import matplotlib.pyplot as plt

# Frame rate 15 fps
sleep_time = 1.0/15.0

# Setup video capture
cap = cv2.VideoCapture(0) # From camera 0
if cap.isOpened()==False:
    print("Camera init failed")
    exit(1)

# Processing ...
while cap.isOpened():
    # Get next frame
    ret,frame = cap.read()

    # Display
    cv2.imshow('frame',frame)
    time.sleep(sleep_time)
    if cv2.waitKey(10) & 0xFF==27:
        break

cap.release()
cv2.destroyAllWindows()

Thanks!

Hi,

I just check your source on JetPack4.4 DP + Xavier and the code runs well without issue.
Do you use JetPack4.4? If not, would you mind to give it a try?

Thanks.

Hi AastaLLL,

Actually the issue happened in the intermediate code of my project.
If I substitute the function of cv2.imwrite for the function of cv2.image(), it won’t happen the error.

I did a small test in order to reproduce the same error, but the output message is still a little big different. (I got another message but I don’t know whether it caused from same issue or not.)

Code Part:

File name : cv2_imshow_test.py

import numpy as np
import cv2

img = cv2.imread('test.png')
img_gray = cv2.imread('test.png', cv2.IMREAD_GRAYSCALE)
cv2.imshow('My image',img_gray)

cv2.waitKey(0)
cv2.destroyAllWindows

Output:

$ python3 cv2_imshow_test.py

Gtk-Message: 11:15:07.899: Failed to load module "canberra-gtk-module" 

Even I tested this command, but the error was still same.

$ sudo apt-get install libcanberra-gtk3-module

Reading package lists... Done
Building dependency tree
Reading state information... Done
libcanberra-gtk3-module is already the newest version (0.30-5ubuntu1).
0 upgraded, 0 newly installed, 0 to remove and 90 not upgraded.

Thank you for your attention about my issue!
BR,
Chieh


BTW, I already tested @pleopard file, but unfortunately I didn’t equip a camera so I cannot do a complete test for your script.

Hi,

Sorry for the late update.

Test the sample above, we can display the image without issue.
This error is a harmless warning and won’t affect the OpenCV functionality.

Gtk-Message: 15:00:07.664: Failed to load module "canberra-gtk-module"

A possible issue is that if you remote login the device with ssh.
Please remember to add -X argument to redirect the DISPLAY into the local.
Ex.

$ ssh -X nvidia@[IP]

Thanks