Qengineering/Jetson-Nano-image

OpenCV QT-Support

cjjaeckson opened this issue · 16 comments

Hi Qengineers!
First of all: Thanks a lot for that awsome image!! Before, I had huge problems with installing Yolo-dependencies because of missing python 3.7. Now, its perfectly working. ;)
But: It came out another issue with preinstalled opencv. For my project I want to visualize a webcamstream on a hdmi-connected display. Using the cv2.imwrite function always outputs the following error message:

qt.qpa.xcb: could not connect to display 
qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "/home/jetson/.local/lib/python3.8/site-packages/cv2/qt/plugins" even though it was found.
This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.

Available platform plugins are: xcb.

Aborted (core dumped)

It seems like WITH_QT variable was disabled on installation. Is there a possibility to enable qt support afterwards? Or does somebody has another solution for me?

Thanks a lot!
Chris

@cjjaeckson,

In this case, you have to re-install OpenCV with the -D WITH_QT=ON switch.
It will take a while to build (hours!). Also, keep your swap space large enough.
You can either follow the guide, or use one of the scripts based on the tutorial.

Oh wow! Thanks for the answer and for help!
I installed qt with the given guide, but still have the same problem. Do I first have to uninstall the preinstalled opencv version of the image? I thought it will overwrite it...

Dear @cjjaeckson,

I'm beginning to worry somewhat. OpenCV overwrites its previous installation. It should work by now.
You could test the Qt5 part by displaying a simple window. It must be like the one below.
image
A menu at the top, and some info in a status bar at the bottom.
If you see such a screen, you know OpenCV is using Qt5 without problems.

Googling your issue seems a common one.
One last thing. Did you install OpenCV also with a pip3 install opencv or pip3 install opencv-python?
In that case, you have two installations along each other. That's asking for problems.

Hi!

Thank you for your support, it helps a lot.
The last few days I have tried 4 or 5 times to get it to run. The first time manually on my old Ubuntu image. Then via the shell script you provided. After all that didn't work, I completely rebuilt the image and tried twice more with the shell script. All unfortunately without success.
I get the following error message when testing:
OpenCV_ErrorMessage

To use the shell script I had to delete python-pip package, because it seems to have been replaced by python3-pip and could not be installed. The shell script I used at the end is in the annex.
I have saved the logs of the last attempt in a file. Maybe someone with a little more background knowledge can discover something there. I am unfortunately still a beginner, what concerns that.
To answer your question: I never used pip install to install opencv. All is built on your image.

I hope that I can be helped!

Thanks in advance.

Christian

output.txt
OpenCV-4-7-0.txt

That is a good old friend of mine, the static TLS block issue.
Please see this discussion.

Well, I solved that problem by switching the import order. Thanks for the link.
But now again...nothing on screen.
My testing script:

import numpy as np
from matplotlib import pyplot as plt
import cv2

img = cv2.imread('watch.jpg',cv2.IMREAD_GRAYSCALE)
cv2.imshow('image',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

Error message:
OpenCV_ErrorMessage

Maybe I have to accept that sometimes there comes a time to give up. :D
Oh man...

@cjjaeckson,

I think Google is your best friend here.
After just one search with Raspberry Pi qt.qpa.xcb: could not connect to display, it came with a lot of solutions

Yes, sorry. You are completely right!
Now at least its displaying something. I still have a warning but for now I will ignore it.
For documentation:
Your good old friend, the static TLS block issue is solved with:

export LD_PRELOAD=/usr/lib/aarch64-linux-gnu/libgomp.so.1

The qt.qpa.xcp display issue I solved with:

export DISPLAY=:0.0

The display issue just appears if you are working remotely via ssh.
Thanks a lot for your help!
Chris

You're welcome.

bykhov commented

The display issue just appears if you are working remotely via ssh.

Is there a way to use cv2.imshow via remote ssh or remote Jupyterlab?

It just informs: Gtk-WARNING **: cannot open display:

Both are command line interfaces, not capable of transferring video. Sorry.

bykhov commented

Thanks, it was fast.
Is there a conceptual difference between plt.imshow that works and cv2.imshow that is not?

Indeed, plt.imshow is vector based, cv2.imshow is pixel based.

Hey @Qengineering , I had recently installed OpenCV 4.5.3 with CUDA support for my Jetson Nano using the installation script, provided in the website. But now, when I'm trying to run any program with cv2.imshow(), it just says, it has no module named imshow. Even when I tried to print cv2.version, the Python3 command line said, that cv2 has no module named version.

Is it because of the QT=OFF flag, used during build?

@francojoem,

No. The QT=OFF flag only disables only a few additional Qt modules. Surely not a complete Python installation!

It seems a part of the installation fails.
If you give the CMake command it completes with an overview. Here you must see which Python installation is being used.

image

@Qengineering , the catch over here is that when I open jtop, it still shows OpenCV 4.5.3 with CUDA:YES . I don't know what might be the issue, would have to try reinstalling the build.