opencv-python icon indicating copy to clipboard operation
opencv-python copied to clipboard

opencv GUI does not work

Open braindevices opened this issue 9 years ago • 91 comments

cv2.namedWindow('test', cv2.WINDOW_AUTOSIZE) results in an error:

QObject::moveToThread: Current thread (0xca9110) is not the object's thread (0x1256140).
Cannot move to target thread (0xca9110)

here is the version:

cv2.__version__
Out[3]: '3.3.0'
QtCore.QT_VERSION_STR
Out[7]: '5.6.2'

braindevices avatar Sep 12 '17 07:09 braindevices

Same error at all imshow calls This could be from lacking swap space at large images (my swap is completely missing) I have 5000 image here and it works if the image is less than 60K (and no sudo on command line) = this is a int to long conversion error in the swap space (I also found this error in the first Unix version of Kernigham and Ritchie - did you copy some code from there :-) ? )

It works well with smaller images (and stop working with sudo python3 .... works only with python3 ....)

cv2.imshow("Input", image)
cv2.imshow("Original", faceOrig)

My workaround is this convert -strip -interlace Plane -gaussian-blur 0.05 -quality 85% DSC_0372.JPG DSC_0372_c85.JPG until the image is under 64k

dorinionescu avatar Apr 02 '18 13:04 dorinionescu

same errors

WuXinyang2012 avatar Apr 20 '18 13:04 WuXinyang2012

Could anyone give a good answer? The same problem happened to me as well. Thanks in advance.

RunningLeon avatar May 22 '18 05:05 RunningLeon

There's no solution but I suspect that the issue has something to do with conflicts between multiple Qt's.

skvark avatar May 22 '18 06:05 skvark

@skvark Thanks for your quick response. But it's really bothering me. I'm using anaconda3 and all my envs that have opencv-python have crashed.

RunningLeon avatar May 22 '18 06:05 RunningLeon

I didn't have this issue at first, then cv2.namedWindow just stopped working for me without me making any system changes. I noticed in dmesg the following: python[29883]: segfault at 0 ip 00007fa8c3c114be sp 00007ffcf5c34740 error 4 in libxcb.so.1.1.0[7fa8c3c07000+21000]

After a quick Google, I found this thread, which recommended removing the libqt5x11extras5 package. I just removed that (and the 121 dependent packages), and it's working properly again. So like @skvark mentioned, it's probably due to Qt conflicts.

AwwwwHamburgers avatar May 28 '18 15:05 AwwwwHamburgers

@coxbrandon thank you very much! Same problem, that solution worked like a charm. Thanks a lot! (I also had that number of dependent packages - on Linux Mint).

FedericoPonzi avatar May 31 '18 18:05 FedericoPonzi

If you have this issue: try to remove libqt5x11extras5 package (see @coxbrandon's message above) and please report here if that solution works for you. Note: do this at your own risk.

skvark avatar May 31 '18 19:05 skvark

I advise strongly against removing libqt5x11extras5 unless you know exactly what you are doing. It killed my lightdm display manager, and, sadly, didn't fix the issue for me.

Ekkehard avatar Jun 01 '18 20:06 Ekkehard

@Ekkehard, that's why I mentioned there were a number of dependent packages, as sort of a warning that removing it might have undesired consequences. FWIW, I'm running Linux Mint 18 with Cinnamon (and mdm as the display manager), and it looked like the libqt5x11extras5 package was only installed as a result of some KDE thing I installed at one point and never touched again, so I wasn't too concerned with removing it.

Are you seeing the same libxcb.so.1.1.0 segfault error in dmesg I mentioned above whenever you get the QObject::moveToThread issue? Or any other corresponding error in dmesg?

AwwwwHamburgers avatar Jun 02 '18 17:06 AwwwwHamburgers

@coxbrandon, nope, I can see nothing conspicuous in dmsg at all (nor in any of the "usual suspects" other logs).

And you are right, KDE is getting hit hard by removing libqt5x11extras5, so whoever is using KDE (e.g. Kubuntu) is well advised not to remove it (Kdevelop and Kontact had to be re-installed, and a nonfunctional display manager leaves anybody dead in the water who depends on a GUI to do just about anything). That's why I wanted to re-emphasize your warning, in particular since it is hard to know which programs depend on any one of the 120-some-odd packages that get removed right along with that library.

But it could be a hint too, maybe there is some incompatibility with KDE, even if you have only some of its components installed.

Ekkehard avatar Jun 02 '18 18:06 Ekkehard

After some googling with different keywords I found this: https://stackoverflow.com/a/42955557/5795428

It indeed seems that the Qt 4.8.7 which ships with opencv-python somehow conflicts with the system (or some other) Qt installation. I can try to rebuild the Docker images and Qt in them with -qtnamespace Qt flag which should prevent symbol clashes.

skvark avatar Jun 02 '18 18:06 skvark

Hello, I've also encountered this problem. Will you notify us here when you have done?

Thanks in advance

Buckler89 avatar Jun 03 '18 17:06 Buckler89

Right, so i compiled opencv3 and it installs for python2 as well as python3. It requires about 5G of space, and maybe some changing of the runpath for one of the sofiles. Other than that, once installed, the errors with cannot move to thread is resolved and works. You'll need to compile FFmpeg as well. I want to add that uninstalling libqt5x11extras5 package is probably not a good idea as a resolution to a problem like this. Also if one of the sofiles has a runpath that points somewhere where you don't want it, patchelf --force-rpath --set-rpath 'path to library dir' sofile.

muziker avatar Jun 06 '18 11:06 muziker

@skvark an updated release would be great! Also have this issue, uninstalling the package mentioned above would break/uninstall VLC, Albert, CopyQ, Kdenlive and others. Really appreciate your efforts with this project!

linusg avatar Jun 12 '18 20:06 linusg

I'll try to rebuild the Docker images during next weekend and publish a new release after that.

skvark avatar Jun 13 '18 15:06 skvark

New Docker images are now up. I'll publish a new release during next week.

EDIT: Requires more work, the new Qt build is not linked properly...

skvark avatar Jun 24 '18 16:06 skvark

I have to patch OpenCV (add Qt namespace macros to OpenCV Qt GUI code) to make this work.

skvark avatar Jun 26 '18 06:06 skvark

@skvark We are awaiting this patch :)

esitharth avatar Jul 13 '18 19:07 esitharth

I'm afraid the changes were far more complicated than I anticipated. Currently I don't have time to finish patching the OpenCV sources to support namespaced Qt builds. Current priority is to get Python 3.7 support out.

What would be needed is support for namespaced Qt builds (https://wiki.qt.io/Qt_In_Namespace). The problem is that for some reason OpenCV builds and links fine with the namespaced Qt but when the library is imported the Qt symbols are not found. These files need fixes (the issue is in OpenCV, not in this repository):

https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_QT.h https://github.com/opencv/opencv/blob/master/modules/highgui/src/window_QT.cpp

skvark avatar Jul 13 '18 20:07 skvark