Coder Social home page Coder Social logo

opencv GUI does not work about opencv-python HOT 91 CLOSED

opencv avatar opencv commented on July 19, 2024 41
opencv GUI does not work

from opencv-python.

Comments (91)

areche avatar areche commented on July 19, 2024 76

In my case the Qt conflicted with the Qt of the system due to a KDE plugin.

This is how I found it:

export LD_DEBUG=all
This allowed me to see all the libraries that are used.

python cvFail.py 2> output.txt
I reproduce the problem and capture all the errors (which thanks to LD_DEBUG contain all library dependencies)

unset LD_DEBUG
No need to the debug anymore

grep libQt output.txt
Found hundreds of references to Qt, but the more interesting was that two different versions appeared: libQtCore-3dbacd8a.so.4.8.7 (from the virtual environment) and libQtCore.so.4 (from the system)

Using less output.txt search for libQtCore.so.4 to know which other library was loading it. I found that was breeze.so, so I search which other library was loading it and it turn out to be libQtCore-3dbacd8a.so.4.8.7.

Conclusion: The OpenCV distributed Qt tries to load breeze.so and this library then loads the system Qt introducing an inconsistency and making the application crash.

Lets find who install breeze.so
dpkg -S /usr/lib/kde4/plugins/styles/breeze.so
It seems to be a library from a kde style plugin (kde-style-breeze-qt4), so I remove this plugin:

apt-get remove kde-style-breeze-qt4
And my problem was solved! :-)

I hope this helps someone.

from opencv-python.

AwwwwHamburgers avatar AwwwwHamburgers commented on July 19, 2024 31

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.

from opencv-python.

caixiaofan avatar caixiaofan commented on July 19, 2024 30

First, uninstall any versions of OpenCV you may have installed. If you installed using pip:

sudo pip uninstall opencv-python
Next, try installing OpenCV using your Linux distro's package manager. For Ubuntu/Debian, this is:

sudo apt-get install libopencv-dev python-opencv

copy from https://reformatcode.com/code/python/how-to-fix-the-error-quotqobjectmovetothreadquot-in-opencv-in-python

from opencv-python.

Ekkehard avatar Ekkehard commented on July 19, 2024 27

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.

from opencv-python.

skvark avatar skvark commented on July 19, 2024 12

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.

from opencv-python.

saeedranjbar12 avatar saeedranjbar12 commented on July 19, 2024 8

GUI problem with opencv 3.4.0 and ubuntu 16.04 - python 2.7

from opencv-python.

skvark avatar skvark commented on July 19, 2024 6

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.

from opencv-python.

skvark avatar skvark commented on July 19, 2024 6

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

from opencv-python.

mludvig avatar mludvig commented on July 19, 2024 5

I guess the problem is that Ubuntu 16.04 opencv libraries are 2.4.9.1 and that doesn't work with opencv-python 3.x. I've got the same problem here - the apt-installed opencv-python 2.4.9.1 works fine but pip-installed opencv-python 3.4.0 fails with the very same program (simple imread()/imshow()) with:

QObject::moveToThread: Current thread (0x1d7c6c0) is not the object's thread (0x228e340).
Cannot move to target thread (0x1d7c6c0)
Segmentation fault

Unfortunately opencv-python 2.4.9 doesn't support Python3 as far as I know so I'm stuck with Python2 for now.

from opencv-python.

skvark avatar skvark commented on July 19, 2024 5

The precompiled opencv-python packages generated by this repository will not work properly in some GNU/Linux systems. Some solutions:

  • If you need GUI support, build OpenCV python bindings yourself and link the library against your system Qt.
  • If you need GUI support but do not wish to build opencv-python yourself, use opencv-python-headless and install some other Python library which you can use to display images.
  • If you don't need GUI support, just install opencv-python-headless.

from opencv-python.

myaimmystyle avatar myaimmystyle commented on July 19, 2024 5

Hi folks,

I received the same error when working within a virtual environment in Python 3 and opencv 3.3
The following simple steps solved my issue. Hope it helps.

  1. sudo apt-get autoremove
  2. sudo apt-get autoclean
  3. sudo apt-get update

from opencv-python.

jckastel avatar jckastel commented on July 19, 2024 4

I have the same problem with opencv-python 3.4.0.12 (installed via pip) python 3.5.2, ubuntu 16.04.4 LTS, whenever I use cv2.namedWindow or cv2.imshow. No virtualenv, nothing fancy is needed:

Python 3.5.2 (default, Nov 23 2017, 16:37:01) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.namedWindow('test')
QObject::moveToThread: Current thread (0x1aee720) is not the object's thread (0x1fd1f30).
Cannot move to target thread (0x1aee720)

Segmentation fault (core dumped)

Same is true for opencv-contrib-python.

from opencv-python.

oarriaga avatar oarriaga commented on July 19, 2024 4

So I just had the same problem and fixed it for my system (ubuntu 16.04).

I checked in my logs recent installations that contained dependencies with libraries that use Qt
vim /var/log/apt/history.log

Looking in that file I saw that I recently installed okular and that okular installed libraries that depend on Qt.
I removed okular and everything seems to be working now.

sudo apt-get remove okular
sudo apt-get autoremove

from opencv-python.

sibojia avatar sibojia commented on July 19, 2024 3

@caixiaofan This simply lets you use the opencv binding shipped in apt-get and stop using this repo. IMHO issues in this repo should focus on how to solve problems in this library.

from opencv-python.

FedericoPonzi avatar FedericoPonzi commented on July 19, 2024 3

@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).

from opencv-python.

skvark avatar skvark commented on July 19, 2024 3

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...

from opencv-python.

skvark avatar skvark commented on July 19, 2024 3

@chutongz libvpx is a dependency of FFmpeg, it's not related to this issue.

I will repeat myself:

The root of this issue is that opencv-python packages ship with their own Qt build and on some Linux systems there's a system Qt installation which does not play along with the one supplied with opencv-python.

To my understanding, the only way to avoid this issue completely is to use namespaced Qt build (https://wiki.qt.io/Qt_In_Namespace). It would require modifications to OpenCV GUI code to use such build of Qt. This is not practical and cannot be done in this repository. This is why the issue has been marked with a tag "wontfix".

One thing you could try is to check the link order of the dependencies (I don't know if this works):

export LD_DEBUG=all
python you_test_script.py

If that works, it will print the libs which the linker is accessing. See this for more info: http://www.bnikolic.co.uk/blog/linux-ld-debug.html

If you system Qt appears / is linked before the one supplied with opencv-python then the issue could be probably fixed by changing linker search order.

from opencv-python.

BlueSeven277 avatar BlueSeven277 commented on July 19, 2024 3

My problem was caused by QT. before I install QT, my opencv was fine.
I uninstalled QT but it did not help. I finally was able to make it work through "sudo apt-get autoremove libqt5x11extras5".

from opencv-python.

HamedJafarzadeh avatar HamedJafarzadeh commented on July 19, 2024 2

In my case, I did almost all the solutions:

  • installing using pip3 install opencv-python
  • installing using apt install python-opencv
  • I followed @areche solution, I end up with kdelibs5-plugins which was an important module for most of my desktop environments, so I give up on uninstalling it.

Finally, I found a solution for my case

  • pip uninstall opencv-python on all instances of my python and virtual environments
  • pip3 uninstall opencv-python on all instances of my python and virtual environments
  • sudo apt remove python-opencv

then I downloaded the most recent opencv, in my case : opencv-4.1.1 , I build it.
for building :

  • mkdir build; cd build; ccmake ..
    then I pressed pressed c, again pressed c, then pressed g to generate make files, then
  • sudo make -j8
    after successful building, I copied build\lib\python3\cv2.cpython.xxxxxx.so to usr/local/lib/python3.5/dist-packages/ and renamed it to cv2.so

Do the same for each virtualenv that you have. ( I'm not sure if it is logical, but it worked for me).

then everything worked fine without any error.

from opencv-python.

anik-kucse avatar anik-kucse commented on July 19, 2024 2

Thanks @NikkoWei. As I don't want to break my KDE DE I followed your instruction. test code runs perfectly.

It's risky to remove libqt5x11extras5 or kde-style-breeze-qt4 for environment which need the modules.
In my case, I work on Ubuntu with KDE. So libqt5x11extras5 or kde-style-breeze-qt4 are important for my desktop environment.

I found there are Qt conflicts between those in opencv-python package and those in system path. The steps to find the problem are the same as @areche:

  1. Display the library loading problems
    export LD_DEBUG=all
  1. Edit script to cause the problem
# fail.py
import cv2
im = cv2.imread('img.jpg')
cv2.imshow('image',im)
cv2.waitKey(0)
  1. Export the library loading information
    python fail.py 2>output.txt
  1. I found there are two version of Qt are used by loader in output.txt:
    ...

     10836:	symbol=_ZNSbIwSt11char_traitsIwESaIwEEC1ERKS2_;  lookup in file=/home/lnwei/.conda/envs/opencv_test/lib/python3.6/site-packages/cv2/.libs/libQtGui-903938cd.so.4.8.7 [0]
     10836:	symbol=_ZNSbIwSt11char_traitsIwESaIwEEC1ERKS2_;  lookup in file=/home/lnwei/.conda/envs/opencv_test/lib/python3.6/site-packages/cv2/.libs/libQtTest-1183da5d.so.4.8.7 [0]
     10836:	symbol=_ZNSbIwSt11char_traitsIwESaIwEEC1ERKS2_;  lookup in file=/home/lnwei/.conda/envs/opencv_test/lib/python3.6/site-packages/cv2/.libs/libQtCore-6df570dd.so.4.8.7 [0]

     ...

     10836:	symbol=_ZTI14QWindowSurface;  lookup in file=/usr/lib/x86_64-linux-gnu/libQtDBus.so.4 [0]
     10836:	symbol=_ZTI14QWindowSurface;  lookup in file=/usr/lib/x86_64-linux-gnu/libQtCore.so.4 [0]
     10836:	symbol=_ZTI14QWindowSurface;  lookup in file=/usr/lib/x86_64-linux-gnu/libQtGui.so.4 [0]

     ...

As you see, there are two version Qtlib are used: 4.8.7 in the python packages path(I use conda environment) and 4 in the system path.
So it's probably the Qt conflicts.

There are 2 ways to solve this problem:

  1. Rebuild opencv by source to link Qtlib in system path. After make -j8, move the python library of opencv to overwrite the library in your python packages environment

    cp /path/to/build/lib/python3/cv2.cpython-36m-x86_64-linux-gnu.so /home/lnwei/.conda/envs/opencv_test/lib/python3.6/site-packages/cv2/cv2.cpython-36m-x86_64-linux-gnu.so
  2. Just replace Qtlib in the python packages by Qtlib in system (according to output.txt)

    cp /usr/lib/x86_64-linux-gnu/libQtGui.so.4 ./libQtGui-903938cd.so.4.8.7
    
    cp /usr/lib/x86_64-linux-gnu/libQtCore.so.4 ./libQtCore-6df570dd.so.4.8.7 

    I can't find libQtTest in my system path but it make no difference.

The 2 solution are OK for my case.

from opencv-python.

skvark avatar skvark commented on July 19, 2024 1

I'm sorry but I'm still unable to replicate this issue. I took a fresh Ubuntu 16.04.3 Virtualbox image and run multiple different tests and even tried to deliberately break the installation. No errors.

Test script which I used:

import cv2
import numpy as np

print("first window 1")

cv2.namedWindow('test', cv2.WINDOW_AUTOSIZE)
black = np.zeros((400, 400, 3), np.uint8)
cv2.imshow('test')
cv2.waitKey(0)

print("second window 2")

cv2.imshow('test', black)
cv2.waitKey(0)

print("third window 3")

cv2.imshow('test', black)
cv2.waitKey(0)

cv2.destroyAllWindows()

Dynamic linking is OK. The static library which ships with these wheels should look like below when inspected through readelf and ldd. RPATH entry should point to the .libs/ folder which should contain these files:

osboxes@osboxes:~/.local/lib/python3.5/site-packages/cv2/.libs$ ls
libavcodec-7625dabe.so.58.6.103   libQtCore-ba1dc80c.so.4.8.7  libswresample-81cb7b3e.so.3.0.101
libavformat-d3ca1b40.so.58.3.100  libQtGui-6d0f14dd.so.4.8.7   libswscale-bc8d848b.so.5.0.101
libavutil-eaec640f.so.56.5.100    libQtTest-1183da5d.so.4.8.7  libz-a147dcb0.so.1.2.3

Readelf:

osboxes@osboxes:~/Desktop$ readelf -d /home/osboxes/.local/lib/python3.5/site-packages/cv2/cv2.cpython-35m-x86_64-linux-gnu.so

Dynamic section at offset 0x15ea1c8 contains 40 entries:
  Tag        Type                         Name/Value
 0x0000000000000001 (NEEDED)             Shared library: [libz-a147dcb0.so.1.2.3]
 0x0000000000000001 (NEEDED)             Shared library: [libavcodec-7625dabe.so.58.6.103]
 0x0000000000000001 (NEEDED)             Shared library: [libavformat-d3ca1b40.so.58.3.100]
 0x0000000000000001 (NEEDED)             Shared library: [libavutil-eaec640f.so.56.5.100]
 0x0000000000000001 (NEEDED)             Shared library: [libswscale-bc8d848b.so.5.0.101]
 0x0000000000000001 (NEEDED)             Shared library: [libQtGui-6d0f14dd.so.4.8.7]
 0x0000000000000001 (NEEDED)             Shared library: [libQtTest-1183da5d.so.4.8.7]
 0x0000000000000001 (NEEDED)             Shared library: [libQtCore-ba1dc80c.so.4.8.7]
 0x0000000000000001 (NEEDED)             Shared library: [libdl.so.2]
 0x0000000000000001 (NEEDED)             Shared library: [libpthread.so.0]
 0x0000000000000001 (NEEDED)             Shared library: [librt.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libstdc++.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]
 0x000000000000000f (RPATH)              Library rpath: [$ORIGIN/.libs]

ldd:

osboxes@osboxes:~/Desktop$ ldd /home/osboxes/.local/lib/python3.5/site-packages/cv2/cv2.cpython-35m-x86_64-linux-gnu.so	
        linux-vdso.so.1 =>  (0x00007ffc0c7e1000)
	libz-a147dcb0.so.1.2.3 => /home/osboxes/.local/lib/python3.5/site-packages/cv2/.libs/libz-a147dcb0.so.1.2.3 (0x00007f77571f0000)
	libavcodec-7625dabe.so.58.6.103 => /home/osboxes/.local/lib/python3.5/site-packages/cv2/.libs/libavcodec-7625dabe.so.58.6.103 (0x00007f7755a6b000)
	libavformat-d3ca1b40.so.58.3.100 => /home/osboxes/.local/lib/python3.5/site-packages/cv2/.libs/libavformat-d3ca1b40.so.58.3.100 (0x00007f775562a000)
	libavutil-eaec640f.so.56.5.100 => /home/osboxes/.local/lib/python3.5/site-packages/cv2/.libs/libavutil-eaec640f.so.56.5.100 (0x00007f77553b5000)
	libswscale-bc8d848b.so.5.0.101 => /home/osboxes/.local/lib/python3.5/site-packages/cv2/.libs/libswscale-bc8d848b.so.5.0.101 (0x00007f775512b000)
	libQtGui-6d0f14dd.so.4.8.7 => /home/osboxes/.local/lib/python3.5/site-packages/cv2/.libs/libQtGui-6d0f14dd.so.4.8.7 (0x00007f775429a000)
	libQtTest-1183da5d.so.4.8.7 => /home/osboxes/.local/lib/python3.5/site-packages/cv2/.libs/libQtTest-1183da5d.so.4.8.7 (0x00007f775406d000)
	libQtCore-ba1dc80c.so.4.8.7 => /home/osboxes/.local/lib/python3.5/site-packages/cv2/.libs/libQtCore-ba1dc80c.so.4.8.7 (0x00007f7753b60000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7753942000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7753725000)
	librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f775351c000)
	libstdc++.so.6 => /usr/lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007f775319a000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7752e91000)
	libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7752c7a000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f77528b0000)
	/lib64/ld-linux-x86-64.so.2 (0x0000564f070bb000)
	libswresample-81cb7b3e.so.3.0.101 => /home/osboxes/.local/lib/python3.5/site-packages/cv2/.libs/libswresample-81cb7b3e.so.3.0.101 (0x00007f7752692000)
	libgthread-2.0.so.0 => /usr/lib/x86_64-linux-gnu/libgthread-2.0.so.0 (0x00007f775248f000)
	libglib-2.0.so.0 => /lib/x86_64-linux-gnu/libglib-2.0.so.0 (0x00007f775217e000)
	libSM.so.6 => /usr/lib/x86_64-linux-gnu/libSM.so.6 (0x00007f7751f75000)
	libICE.so.6 => /usr/lib/x86_64-linux-gnu/libICE.so.6 (0x00007f7751d5b000)
	libXrender.so.1 => /usr/lib/x86_64-linux-gnu/libXrender.so.1 (0x00007f7751b51000)
	libXext.so.6 => /usr/lib/x86_64-linux-gnu/libXext.so.6 (0x00007f775193e000)
	libX11.so.6 => /usr/lib/x86_64-linux-gnu/libX11.so.6 (0x00007f7751604000)
	libpcre.so.3 => /lib/x86_64-linux-gnu/libpcre.so.3 (0x00007f7751393000)
	libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007f775118e000)
	libxcb.so.1 => /usr/lib/x86_64-linux-gnu/libxcb.so.1 (0x00007f7750f6c000)
	libXau.so.6 => /usr/lib/x86_64-linux-gnu/libXau.so.6 (0x00007f7750d67000)
	libXdmcp.so.6 => /usr/lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007f7750b61000)

I did also sudo apt-get install libopencv-dev python-opencv and installed pip install opencv-python next to it (do not do this) but nothing broke.

To be able to fix this or to provide some solution, I still need more information. This means that every thing related to these is important:

  • FULL EXAMPLE of the script which produces this error, one line is not simply enough
  • exact steps which were used to install opencv-python
  • possible other conflicting OpenCV installations
  • anything related to Qt
  • are you using virtual environment or not
  • has the Ubuntu envinroment been modified somehow

Please note that opencv-python versions < 3.3.0.10 do not support GUI functionality and thus support for it cannot be enabled in them without a full rebuild which is impossible because the packages are pre-built. So if you see this error, you are using too old package:

error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script

Releases page contains changelogs for this package: https://github.com/skvark/opencv-python/releases

from opencv-python.

Ekkehard avatar Ekkehard commented on July 19, 2024 1

from opencv-python.

skvark avatar skvark commented on July 19, 2024 1

Most likely older Qt versions work better together with the Qt 4.8.7 which is bundled in the opencv-python wheels. The only real fix for this is the namespaced Qt build but unfortunately it's impossible to use it since being compatible with it would require a rewrite of the OpenCV Qt GUI code.

I tried to initially enable GTK but it got too complicated / impossible due to the many dependencies GTK has. These all depedencies must be available or built on the CentOS 5 environment which in turn is used to build the wheels.

CentOS 5 is a very old release. The manylinux1 format requires that the wheels are built on that old version to be compatible with as many as possible GNU/Linux distributions. Manylinux2 (pypa/manylinux#152) will update the requirement to CentOS 6.x, which will be hopefully easier to work with and makes it possible to either switch to Gtk or upgrade Qt to the most recent version.

In any case, it's most likely to impossible to provide pre-built packages which satisfy the needs of all users on all different platforms. There's always some compromise which has to be made considering the complexity of OpenCV.

from opencv-python.

haimat avatar haimat commented on July 19, 2024 1

Just for the records: This does not help with the issue related to this package here, but you might solve your problem by installing OpenCV with Python bindings from source, as described here:

https://www.pyimagesearch.com/2018/08/15/how-to-install-opencv-4-on-ubuntu/

Solved it for me!

from opencv-python.

Baby47 avatar Baby47 commented on July 19, 2024 1

thanks for your reply about this issue, @skvark, @chutongz,
I meet the same error when using opencv-python:QObject::moveToThread: Current thread (0x22e7370) is not the object's thread (0x238fed0).
Cannot move to target thread (0x22e7370)

and I reinstall opencv-python under conda environment, now i can not even import cv2 under anaconda environment. It makes an error like this: ImportError: libavcodec-7625dabe.so.58.6.103: cannot open shared object file: No such file or directory

/usr/local/lib/python3.5/dist-packages/cv2/.libs$ ls
libavcodec-eac15e48.so.58.21.104 libQtTest-1183da5d.so.4.8.7
libavformat-b6bcbe33.so.58.17.101 libswresample-b4363bfa.so.3.2.100
libavutil-e1b1a17d.so.56.18.102 libswscale-15b3fdc6.so.5.2.100
libQtCore-9549151f.so.4.8.7 libvpx-81a43c0a.so.5.0.0
libQtGui-6d0f14dd.so.4.8.7 libz-a147dcb0.so.1.2.3

All this files do not exist, How can i fix it ?
Thanks for your help

from opencv-python.

Coderx7 avatar Coderx7 commented on July 19, 2024 1

For those having this issue in Anaconda installation, just pip uninstall your opencv-python , and install opencv using conda :

conda install -c conda-forge opencv

that should fix your problems.

from opencv-python.

skvark avatar skvark commented on July 19, 2024

On which operating system? This is probably a bug in OpenCV or in your code and there's nothing I can do about it.

And no need to report Qt version, wheels have Qt 4.8.7 embedded inside them. They do not use your system's Qt version.

Are you sure you are using the prebuilt wheels?

from opencv-python.

braindevices avatar braindevices commented on July 19, 2024

yepp, using prebuilt wheels. It is on ubuntu 14.04

from opencv-python.

skvark avatar skvark commented on July 19, 2024

Works fine on Ubuntu 14.04:

screenshot from 2017-09-12 17_02_04

Can you post more code?

from opencv-python.

TechnoConserve avatar TechnoConserve commented on July 19, 2024

I get the same error when attempting cv2.namedWindow('test', cv2.WINDOW_AUTOSIZE), but only when using python3.5

I'm on Ubuntu 16.04.

from opencv-python.

techdragon avatar techdragon commented on July 19, 2024

@braindevices @TechnoConserve can you provide more information about your Ubuntu environment, the output of which -a python3, which -a pip, pip freeze, env (Always remember to check for any secret information that shouldn't be shared such as API keys or other items before you post the output of env) , and apt list --installed would all prove useful.

from opencv-python.

TechnoConserve avatar TechnoConserve commented on July 19, 2024
uname -a
Linux ave-GL552VW 4.10.0-35-generic #39~16.04.1-Ubuntu SMP Wed Sep 13 09:02:42 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
which -a python3
/home/ave/venv/opencv/bin/python3
/home/ave/venv/potato/bin/python3
/usr/bin/python3
which -a pip
/home/ave/venv/potato/bin/pip
/home/ave/.local/bin/pip
/usr/local/bin/pip
/usr/bin/pip

That does seem puzzling to me since it only picked up pip in one of my virtual environments regardless of whether I have the opencv virtual environment active or not.

pip freeze
apparmor==2.10.95
apparmor.click==0.3.13.1
apt-xapian-index==0.47
apturl==0.5.2
awscli==1.11.155
beautifulsoup4==4.6.0
blinker==1.3
botocore==1.7.13
Brlapi==0.6.4
certifi==2017.7.27.1
chardet==3.0.4
checkbox-support==0.22
click==0.4.43+16.4.20170613.0ubuntu1
colorama==0.3.7
command-not-found==0.3
cryptography==1.2.3
defer==1.0.6
Django==1.11.5
django-modelcluster==3.1
django-taggit==0.22.1
django-treebeard==4.1.2
djangorestframework==3.6.4
docutils==0.14
feedparser==5.1.3
guacamole==0.9.2
html5lib==0.999
httplib2==0.9.1
idna==2.6
Jinja2==2.8
jmespath==0.9.3
language-selector==0.1
LibAppArmor==2.10.95
louis==2.6.4
lxml==3.5.0
Mako==1.0.3
MarkupSafe==0.23
numpy==1.13.1
oauthlib==1.0.3
onboard==1.2.0
opencv-python==3.3.0.10
padme==1.1.1
pexpect==4.0.1
Pillow==3.1.2
pkg-resources==0.0.0
plainbox==0.25
psycopg2==2.7.3.1
ptyprocess==0.5
pyasn1==0.3.5
pycups==1.9.73
pycurl==7.43.0
pygobject==3.20.0
PyJWT==1.3.0
pyparsing==2.0.3
python-apt==1.1.0b1
python-dateutil==2.6.1
python-debian==0.1.27
python-gnupg==0.3.8
python-systemd==231
pytz==2017.2
pyxdg==0.25
PyYAML==3.12
reportlab==3.3.0
requests==2.18.4
rsa==3.4.2
s3transfer==0.1.11
sessioninstaller==0.0.0
six==1.11.0
system-image==3.1
system-service==0.3
ubuntu-drivers-common==0.0.0
ufw==0.35
unattended-upgrades==0.1
Unidecode==0.4.21
unity-scope-calculator==0.1
unity-scope-chromiumbookmarks==0.1
unity-scope-colourlovers==0.1
unity-scope-devhelp==0.1
unity-scope-firefoxbookmarks==0.1
unity-scope-manpages==0.1
unity-scope-openclipart==0.1
unity-scope-texdoc==0.1
unity-scope-tomboy==0.1
unity-scope-virtualbox==0.1
unity-scope-yelp==0.1
unity-scope-zotero==0.1
urllib3==1.22
usb-creator==0.3.0
uWSGI==2.0.15
wagtail==1.12.2
Willow==0.4
xdiagnose==3.8.4.1
xkit==0.0.0
XlsxWriter==0.7.3
env
XDG_VTNR=7
KDE_MULTIHEAD=false
SSH_AGENT_PID=2482
XDG_SESSION_ID=2
PAM_KWALLET5_LOGIN=/tmp/kwallet5_ave.socket
TERM=xterm
SHELL=/bin/bash
KONSOLE_DBUS_SERVICE=:1.31
GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/ave/.gtkrc-2.0:/home/ave/.config/gtkrc-2.0
KONSOLE_PROFILE_NAME=Green
QT_LINUX_ACCESSIBILITY_ALWAYS_ON=1
GS_LIB=/home/ave/.fonts
GTK_RC_FILES=/etc/gtk/gtkrc:/home/ave/.gtkrc:/home/ave/.config/gtkrc
WINDOWID=58720261
OLDPWD=/home/ave/PycharmProjects/potato-project/potato
SHELL_SESSION_ID=b8195832c1774000aa88ccc122cc6b7b
GTK_MODULES=gail:atk-bridge
XDG_SESSION_CLASS=user
KDE_FULL_SESSION=true
USER=ave
QT_ACCESSIBILITY=1
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session1
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
SSH_AUTH_SOCK=/tmp/ssh-YXVwNQB4fLBl/agent.2436
SESSION_MANAGER=local/ave-GL552VW:@/tmp/.ICE-unix/2732,unix/ave-GL552VW:/tmp/.ICE-unix/2732
DEFAULTS_PATH=/usr/share/gconf//usr/share/xsessions/plasma.default.path
VIRTUAL_ENV=/home/ave/venv/opencv
XDG_CONFIG_DIRS=/etc/xdg/xdg-/usr/share/xsessions/plasma:/etc/xdg:/usr/share/kubuntu-default-settings/kf5-settings
DESKTOP_SESSION=/usr/share/xsessions/plasma
PATH=/home/ave/venv/opencv/bin:/home/ave/venv/potato/bin:/home/ave/bin:/home/ave/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
QT_IM_MODULE=compose
QT_QPA_PLATFORMTHEME=kde
PWD=/home/ave/venv
XDG_SESSION_TYPE=x11
LANG=en_US.UTF-8
KDE_SESSION_UID=1000
MANDATORY_PATH=/usr/share/gconf//usr/share/xsessions/plasma.mandatory.path
PS1=(opencv) \[\e]0;\u@\h: \w\a\]${debian_chroot:+($debian_chroot)}\u@\h:\w\$ 
KONSOLE_DBUS_SESSION=/Sessions/1
GTK2_MODULES=overlay-scrollbar
COLORFGBG=15;0
HOME=/home/ave
SHLVL=2
XDG_SEAT=seat0
KDE_SESSION_VERSION=5
LANGUAGE=
XCURSOR_THEME=breeze_cursors
LOGNAME=ave
XDG_SESSION_DESKTOP=KDE
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-UiuOcMuIpB,guid=2d3de9776ef25a2171e6481959c98ad4
XDG_DATA_DIRS=/usr/share//usr/share/xsessions/plasma:/usr/local/share/:/usr/share/:/var/lib/snapd/desktop
LESSOPEN=| /usr/bin/lesspipe %s
XDG_RUNTIME_DIR=/run/user/1000
DISPLAY=:0
PROFILEHOME=
XDG_CURRENT_DESKTOP=KDE
PAM_KWALLET_LOGIN=/tmp/kwallet_ave.socket
LESSCLOSE=/usr/bin/lesspipe %s %s
ZADDR=zcbZsZdkHfGqbgUjZuM7KiJ7x2ayXLLbXfB8eryRqatW64hhqRK7W74Whjq95jFHKzyTYbnTFnNZBRM8cJ9Q6hVcGGWd7BT
XAUTHORITY=/tmp/xauth-1000-_0
_=/usr/bin/env

from opencv-python.

dzimmerer avatar dzimmerer commented on July 19, 2024

Same error (also on 16.04 with python 3.5)

from opencv-python.

djokjulapfe avatar djokjulapfe commented on July 19, 2024

Same error on Ubuntu 16.04 with python 3.5. Beaks at cv2.imshow('Test', img)

from opencv-python.

sibojia avatar sibojia commented on July 19, 2024

Same error on Ubuntu 16.04 with python 2.7. Prints hundreds of error:


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

When calling cv2.waitKey() for the first time in a process. No other effects but the messages are very annoying.
cv2.__version__ = 3.3.0

from opencv-python.

ridho9 avatar ridho9 commented on July 19, 2024

Same here, opencv 3.3.0 and ubuntu 16.04
Trying cv2.namedWindow('test', cv2.WINDOW_AUTOSIZE) with 3.3.0.10 returns the same QObject error, but using 3.2.0.8 returns

<ipython-input-3-2efaecccc8a8> in <module>()
----> 1 cv2.namedWindow('test', cv2.WINDOW_AUTOSIZE)

error: /io/opencv/modules/highgui/src/window.cpp:565: error: (-2) The function is not implemented. Rebuild the library with Windows, GTK+ 2.x or Carbon support. If you are on Ubuntu or Debian, install libgtk2.0-dev and pkg-config, then re-run cmake or configure script in function cvNamedWindow

And I already have installed libgtk2.0-dev and pkg-config

from opencv-python.

ibrmora avatar ibrmora commented on July 19, 2024

Same here, opencv 3.3.0.10 and ubuntu 16.04 with python 3.5.2 cv2.imshow("image", image)

from opencv-python.

martingra avatar martingra commented on July 19, 2024

Hi. Having the same problem!

  • OS: Ubuntu 16.04 LTS
  • Trying to run the script posted by @skvark:
    `import cv2
    import numpy as np

print("first window 1")

cv2.namedWindow('test', cv2.WINDOW_AUTOSIZE)
black = np.zeros((400, 400, 3), np.uint8)
cv2.imshow('test')
cv2.waitKey(0)

print("second window 2")

cv2.imshow('test', black)
cv2.waitKey(0)

print("third window 3")

cv2.imshow('test', black)
cv2.waitKey(0)

cv2.destroyAllWindows()`

  • To install OpenCv, I am using a Virtual Environment using Python 3.5. After activating this environment, and using pip install, I installed opencv-python using pip install opencv-python.

  • Related with PyQT4, I installed it using sudo-apt get install and downloading source and runing make install inside the environment, but for some reason, I'm not finding this packaged listed in the File->Settings-> Project Interpreter section of my PyCharm IDE. I dont know if this may be the problem

The error that is showing to me is:

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

when it gets to the execution of cv2.imshow('test')

Thank you for your help! I'm really stucked in here!

from opencv-python.

ujsyehao avatar ujsyehao commented on July 19, 2024

@saeedranjbar12 I run into this problem too, So how to solve it?

from opencv-python.

skvark avatar skvark commented on July 19, 2024

As I have written earlier, I can't replicate this behaviour with clean Ubuntu 16.04.4 image. Those two lines of code are not enough. I need more information about the environment because issue is most likely in some combination of other installed software (like PyQt) and opencv-python. OpenCV binaries which ship with these packages are built with the standard OpenCV toolchain and it's unlikely that there's something wrong with them. This seems to be very focused on Ubuntu and some rare cases under it which makes it very hard to replicate and debug the issue.

from opencv-python.

dorinionescu avatar dorinionescu commented on July 19, 2024

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

from opencv-python.

WuXinyang2012 avatar WuXinyang2012 commented on July 19, 2024

same errors

from opencv-python.

RunningLeon avatar RunningLeon commented on July 19, 2024

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

from opencv-python.

skvark avatar skvark commented on July 19, 2024

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

from opencv-python.

RunningLeon avatar RunningLeon commented on July 19, 2024

@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.

from opencv-python.

AwwwwHamburgers avatar AwwwwHamburgers commented on July 19, 2024

@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?

from opencv-python.

Ekkehard avatar Ekkehard commented on July 19, 2024

@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.

from opencv-python.

Buckler89 avatar Buckler89 commented on July 19, 2024

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

Thanks in advance

from opencv-python.

muziker avatar muziker commented on July 19, 2024

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.

from opencv-python.

linusg avatar linusg commented on July 19, 2024

@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!

from opencv-python.

skvark avatar skvark commented on July 19, 2024

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

from opencv-python.

esitharth avatar esitharth commented on July 19, 2024

@skvark We are awaiting this patch :)

from opencv-python.

skvark avatar skvark commented on July 19, 2024

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

from opencv-python.

uhdzf avatar uhdzf commented on July 19, 2024

I removed libqt5x11extras5 but my display manager (kde plasma) broke. Seems like its no solution for me :(

from opencv-python.

andyvk85 avatar andyvk85 commented on July 19, 2024

Unfortunately, I also suffer from this bug. I hope some smart person can fix it.

from opencv-python.

RunningLeon avatar RunningLeon commented on July 19, 2024

Have met this problem twice. Changing qt5 to qt4 works for me.

from opencv-python.

ThomasWMarshall avatar ThomasWMarshall commented on July 19, 2024

I also have this issue. Any updates on potential fixes?

from opencv-python.

skvark avatar skvark commented on July 19, 2024

The status is the same as before: OpenCV does not support namespaced Qt builds -> this issue cannot be fixed: #46 (comment)

from opencv-python.

ThomasWMarshall avatar ThomasWMarshall commented on July 19, 2024

@skvark Just out of curiosity, I do have a KDE Neon install on which opencv works with gui support. It's using Qt 5.11.1. My other Neon install, which is a newer version, doesn't work. Do you know why it might work sometimes out of the box?

Additionally, might there be a way to run the guis with GTK instead of Qt?

from opencv-python.

SreenivasVRao avatar SreenivasVRao commented on July 19, 2024

Just want to pitch in and say, I used opencv-python for CV 3.4.3, and while I do get the same "cannot move to target thread" error, the imshow, and waitKey() functions work fine.

Building from source, I remember the focus would switch to the imshow() window. I see that behaviour when I try imshow(), waitKey(0), and destroyAllWindows() in pycharm. However, on the terminal, the focus doesn't switch, but the window does appear, and when I alt-tab to that window, the behaviour is as expected.

It's a weird bug, and I'm sure @skvark must have spent a lot of time on it, but not something that's breaking my workflow.

for reference,
python 2.7
opencv-python 3.4.3.18
virtualenv 16.0.0
Ubuntu 16.04

QMake version 3.0
Using Qt version 5.5.1 in /usr/lib/x86_64-linux-gnu

Happy to pitch in with any further info. Thanks a lot @skvark for your work on this. I've spent hours and hours getting OpenCV running with Python before, and these pip binaries are the best ever!

from opencv-python.

lagvier avatar lagvier commented on July 19, 2024

I had two openCV (opencv-contrib-python==3.4.3.18 and opencv-python==3.4.1.15) on python 3.5, ubuntu 16.04. When I ran
sudo pip uninstall opencv-python
it unistalled opencv-python-3.4.1.15. I no longer get the same errors

from opencv-python.

alexpashevich avatar alexpashevich commented on July 19, 2024

Same problem. Tried updating to opencv-contrib-python(3.4.3.18, 3.4.4.19), as well as multiple versions of opencv-python (3.1.0.0+). Version for python2 (2.4.9.1) works fine but it does not support python3. Thank you for looking into the problem!

from opencv-python.

chutongz avatar chutongz commented on July 19, 2024

I meet the same issue, and I used opencv-python&opencv-contrib-python=3.4.4.19 at the beginning, and then I updated to 4.0.0 but still have this error.
And also I tried on both python2.7 and python 3.5 on Ubuntu 16.04...
I find the libs of opencv have one more lib file than @skvark you showed before, which is libvpx-81a43c0a.so.5.0.0:

/usr/local/lib/python3.5/dist-packages/cv2/.libs$ ls
libavcodec-eac15e48.so.58.21.104   libQtTest-1183da5d.so.4.8.7
libavformat-b6bcbe33.so.58.17.101  libswresample-b4363bfa.so.3.2.100
libavutil-e1b1a17d.so.56.18.102    libswscale-15b3fdc6.so.5.2.100
libQtCore-9549151f.so.4.8.7        libvpx-81a43c0a.so.5.0.0
libQtGui-6d0f14dd.so.4.8.7         libz-a147dcb0.so.1.2.3

Idk if this matters.
And my test code is:

$ python
Python 3.5.2 (default, Nov 12 2018, 13:43:14) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.0.0'
>>> im = cv2.imread('./data/cage/106018878.jpg')
>>> im.shape
(256, 256, 3)
>>> cv2.imshow('image', im)
QObject::moveToThread: Current thread (0x22e7370) is not the object's thread (0x238fed0).
Cannot move to target thread (0x22e7370)

Segmentation fault (core dumped)

And the function cv2.namedWindow() has ths same error while cv2.waitKey(0) works fine.
And I show the Qt version if it could help

$ qmake -v
QMake version 2.01a
Using Qt version 4.8.7 in /usr/lib/x86_64-linux-gnu

from opencv-python.

richardARPANET avatar richardARPANET commented on July 19, 2024

Doing this #46 (comment)

Borked my entire system and had to spend over an hour recovering it.

from opencv-python.

martin3000 avatar martin3000 commented on July 19, 2024

How can I find out what the different Qt versions are?

from opencv-python.

bayvehbi avatar bayvehbi commented on July 19, 2024

i was having the same problem on ubuntu 18. compiling the opencv from source solved this issue.
its clearly about qt so in cmake configurations i used
-D WITH_GTK=ON
instead of
-D WITH_QT=ON
and everything worked fine after this

from opencv-python.

Ekkehard avatar Ekkehard commented on July 19, 2024

from opencv-python.

martin3000 avatar martin3000 commented on July 19, 2024

apt-get remove kde-style-breeze-qt4

Description: Widget style for Qt 4 and KDE Software
This is the default widget style for KDE's Plasma desktop. This
build has the plugin for with Qt 4.
This package is part of the Breeze theme module.

The following packages will be REMOVED:
amarok amarok-utils kde-baseapps-bin kde-runtime kde-style-breeze-qt4

I found that I had opencv installed with apt and another version installed with pip3. After doing a pip3 uninstall, it worked.

from opencv-python.

ryanneph avatar ryanneph commented on July 19, 2024

I also lost Okular (pdf viewer) when uninstalling kde-style-breeze-qt4.

from opencv-python.

native-api avatar native-api commented on July 19, 2024

I had a thought here...
Would it help if we linked to Qt statically? Then there would be no conflicts between two sets of shared entitites 'cuz one of them won't be shared.
The affected users can test this by passing -static to Qt configure in the Dockerfile; I don't know if anything else will need tweaking.

from opencv-python.

skvark avatar skvark commented on July 19, 2024

That could be nice, but licensing is an issue. The LGPL license allows only dynamic linking. Static linking might be possible if some special rules are followed, but as there is a commercial company behind Qt, I would not go with the static linking. Also maintenance would become harder because

(1) If you statically link against an LGPLed library, you must also provide your application in an object (not necessarily source) format, so that a user has the opportunity to modify the library and relink the application. http://www.gnu.org/licenses/gpl-faq.html#LGPLStaticVsDynamic

from opencv-python.

native-api avatar native-api commented on July 19, 2024

The LGPL license allows only dynamic linking.

Not quite, see open source - GPL/LGPL and Static Linking - Stack Overflow (the corresponding part of LGPL is https://www.gnu.org/licenses/lgpl-3.0.html#section4).
We provide the source code for the LGPLed parts in a permitted way1 and the entire work, so we are in the clear here since the user can compile the work with a modified version of the library yada yada.


1By storing the exact version in the result that can be retrieved with getBuildInformation() or by looking at the build scripts and implicitly promising the source code for it will be available on demand (e.g. on the official site) for at least 3 years from our release date.

from opencv-python.

native-api avatar native-api commented on July 19, 2024

We provide the source code for the LGPLed parts in a permitted way and the entire work

I stay (partially) corrected. We provide the source code but we don't oblige the users to do so (MIT license). So if they distribute a version with modifications to our portion and not provide the source, they'll be violating LGPL. Which means that the work as a whole is not effectively under the MIT license...
We re still legally in the clear IMO since we ship all the applicable licenses and say what they apply to, but that's still not a very nice thing to do.

from opencv-python.

native-api avatar native-api commented on July 19, 2024

Anyway, without knowing if linking statically is even possible and solves the problem, legal debates are over nothing.

from opencv-python.

martin3000 avatar martin3000 commented on July 19, 2024

Here I had pip3 install opencv-contrib and apt install python3-opencv, so I had 2 packages. After uninstalling the pip3-package, the problem was gone.

from opencv-python.

fdornelasx avatar fdornelasx commented on July 19, 2024

My problem was caused by QT. before I install QT, my opencv was fine.
I uninstalled QT but it did not help. I finally was able to make it work through "sudo apt-get autoremove libqt5x11extras5".

I did this and now I can't login on my Kubuntu.

Don't do this.

Now I am trying to fix and then I will post the solution...

from opencv-python.

mfahad1 avatar mfahad1 commented on July 19, 2024

@areche hats off to you debugging skills, it solved my problem in no time..

from opencv-python.

harshasunder-1 avatar harshasunder-1 commented on July 19, 2024

Areche debugging procedure above worked for me. In my case the problem library was kdelibs5-plugins which i think got installed with amarok, the music player. I guessed this was the problem library because i saw libQtCore being a part of this library in the output file.

Thanks areche!

from opencv-python.

skvark avatar skvark commented on July 19, 2024

Next opencv-python release will include Qt5 instead of Qt4. That change will most likely solve this issue.

from opencv-python.

native-api avatar native-api commented on July 19, 2024

Next opencv-python release will include Qt5 instead of Qt4. That change will most likely solve this issue.

How? It's going to conflict with any other Qt5 installation present just the same.

from opencv-python.

skvark avatar skvark commented on July 19, 2024

Next opencv-python release will include Qt5 instead of Qt4. That change will most likely solve this issue.

How? It's going to conflict with any other Qt5 installation present just the same.

It's the same major version so I assume it should have better compatibility. But of course there might be still some conflicts.

Edit: by the same version I mean that most of the systems use Qt5 nowadays. Qt4 is very old and the issues might be related only to Qt4 versions.

from opencv-python.

hedoluna avatar hedoluna commented on July 19, 2024

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.

you saved my day!

from opencv-python.

native-api avatar native-api commented on July 19, 2024

Anyway, without knowing if linking statically is even possible and solves the problem, legal debates are over nothing.

FYI, it is possible to link to Qt statically, and we would have to either

  • provide opencv-python and OpenCV source code (and require anyone else who conveys it to do the same) -- i.e. relicense opencv-python as strong copyleft; or
  • provide object files for the closed-source parts that a user would be able to link (statically) with a modified (static) Qt, as well as instructions on how to do this, in some form.

For the 2nd option,

  • I believe the temporary cmake-build directory tree, without the resulting Python module, would qualify. In essence, we need the makefiles to pick up the object files without recompiling them and perform linking for whatever links to Qt and all the way up to the extension module as usual. Not sure if CMake-generated makefiles can do that, or they would complain and require OpenCV sources as well to check if the object files are up to date.
  • An archive of this tree for each release with static Qt would need to be available to opencv-python users somehow -- e.g. at Github releases page (for at least 3 years since release date).
  • LICENSE-3RD-PARTY.txt would need to refer to that location in its Qt section.
  • Anyone who conveys opencv-python would have the same obligation and would either have to rely on us, or (e.g. if they make modifications), provide such an archive themselves and update LICENSE-3RD-PARTY.txt accordingly.

I.e. this is not any easier at all than providing the source code in the first place.


So, I conclude that it would be much easier to update OpenCV to support namespaced Qt -- especially since supporting it is pretty straightforward -- and link against such a Qt.

  • In Linux, it's as trivial as adding a configuration switch to dockerfiles since we compile Qt ourselves
  • In OSX, will have to make a custom Qt formula and compile it from source just like for FFMpeg.

from opencv-python.

freakabcd avatar freakabcd commented on July 19, 2024

I don't have segfaults or crashes; the window just shows up with no content (black bar?) when trying to imshow with the following code:

import cv2
img = cv2.imread('/tmp/foo.png')
cv2.imshow('output', img)
cv2.waitKey(0)

with the aforementioned moveToThread messages:

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

output

/tmp/foo.png is a colour image of size 512x512.

I am on a Manjaro system with python 3.8.3, opencv-python 4.3.0.36, KDE and Qt5 (although this should not matter as opencv-python ships with own version of Qt). Looking through the LD_DEBUG output, I can see the system Qt libs being loaded as a result of an indirect dependency from the opencv-python shipped Qt libs!

   1262759:     file=/usr/lib/qt4/plugins/imageformats/libqgif.so [0];  dynamically loaded by /home/freakabcd/.virtualenvs/opencv/lib/python3.8/site-packages/cv2/../opencv_python.libs/libQtCore-6b7bca35.so.4.8.7 [0]
   1262759:     file=/usr/lib/qt4/plugins/imageformats/libqgif.so [0];  generating link map
   1262759:       dynamic: 0x00007f38b9c68bf8  base: 0x00007f38b9c5f000   size: 0x000000000000a030
   1262759:         entry: 0x00007f38b9c62020  phdr: 0x00007f38b9c5f040  phnum:                  9
   1262759:     
   1262759:     
   1262759:     file=libQtGui.so.4 [0];  needed by /usr/lib/qt4/plugins/imageformats/libqgif.so [0]
   1262759:     find library=libQtGui.so.4 [0]; searching
   1262759:      search cache=/etc/ld.so.cache
   1262759:       trying file=/usr/lib/libQtGui.so.4
   1262759:     
   1262759:     file=libQtGui.so.4 [0];  generating link map
   1262759:       dynamic: 0x00007f38b9ba3540  base: 0x00007f38b909b000   size: 0x0000000000b202c0
   1262759:         entry: 0x00007f38b926c020  phdr: 0x00007f38b909b040  phnum:                  9
   1262759:     
   1262759:     
   1262759:     file=libQtCore.so.4 [0];  needed by /usr/lib/qt4/plugins/imageformats/libqgif.so [0]
   1262759:     find library=libQtCore.so.4 [0]; searching
   1262759:      search cache=/etc/ld.so.cache
   1262759:       trying file=/usr/lib/libQtCore.so.4
   1262759:     
   1262759:     file=libQtCore.so.4 [0];  generating link map
   1262759:       dynamic: 0x00007f38b9094920  base: 0x00007f38b8d98000   size: 0x0000000000302410
   1262759:         entry: 0x00007f38b8e30f60  phdr: 0x00007f38b8d98040  phnum:                 12

As you can see, the opencv-python provided libQtCore is dynamically loading this libqgif.so because it is present in some known path to it /usr/lib/qt4/plugins/imageformats. Given that @areche mentions /usr/lib/kde4/plugins/styles/breeze.so being loaded on their system, it could be that the 4.8.7 Qt shipped with opencv-python is not built correctly to ignore loading plugins from well known "system" paths. I am not even sure if such an option exists in the Qt build configuration as it has been many years since I have built Qt from source.

It would be great if some of the people on this thread with the same issue can check if they have the /usr/lib/qt4/plugins or /usr/lib/kde4/plugins paths showing up in their debug logs (LD_DEBUG=all python myfile.py). If other people can confirm one (or both) of these paths is appearing in their output, someone can check if there is a Qt build config to get rid of searching system paths for plugins to load dynamically.

from opencv-python.

skvark avatar skvark commented on July 19, 2024

@freakabcd See #362

The latest issue with Qt4 is related to the manylinux2014 upgrade. I had to use qt-devel directly from CentOS 7 repos because there were some compiler related issues when I tried to compile Qt4 manually. In older manylinux1 releases Qt4 was compiled manually. Please check the Dockerfiles in the docker folder in this repo for more info. I'll try to upgrade to Qt5 before next release which hopefully solves some of these issues. Plugins path can be set as an env var in Qt5 (like it is set currently in macOS builds in __init__.py), but not in Qt4 based on some fast searches I did earlier.

from opencv-python.

skvark avatar skvark commented on July 19, 2024

Starting from 3.4.10.37 and 4.3.0.38 the pre-built wheels will include Qt 5.15 which has been built in a namespace so the conflict issue should be fixed. The new releases should be up in the next 24 hours. However, please note that I cannot guarantee that the wheels will work on all GNU/Linux systems. The new releases will include also source distributions which should allow to build the wheels locally if you encounter issues with the OpenCV GUI functions.

from opencv-python.

joelcma avatar joelcma commented on July 19, 2024

I would just like to add that I get this same error on 4.3.0.38 and forward but not on 4.3.0.36. I'm running Elementary OS 5.1.7 Hera (Ubuntu based).

I tried updating because cv2.imshow wasn't showing all of my images properly (some were just showing a small box instead of the image) and after updating they show as they should but I'm getting the same QObject::moveToThread error.

from opencv-python.

skvark avatar skvark commented on July 19, 2024

@joelcma Yeah, that "small box" bug was this one which was also caused by a Qt conflict: #362

Can't help much with that QObject::moveToThread error. Just make sure that your Python environment is consistent and you have removed all old versions of opencv-python from there. I have done everything I can to fix the issue.

from opencv-python.

parluo avatar parluo commented on July 19, 2024

It seem that I soved QObject::moveToThread: Current thread is not the objects thread. Cannot move to target thread, byconda uninstall pyqt. But I don't make sure its feasibility. And I found the QT about libs in /usr/lib/x86_64-linux-gnu whill be removed after the commond and every thing is fine now.

from opencv-python.

js899 avatar js899 commented on July 19, 2024

My problem was caused by QT. before I install QT, my opencv was fine.
I uninstalled QT but it did not help. I finally was able to make it work through "sudo apt-get autoremove libqt5x11extras5".

It didn't work for me, I have to submit a project but nothing seems to be working. I have Ubuntu 20.04 LTS, working in Spyder but unable to take videocapture. Please help.

from opencv-python.

GhostDog98 avatar GhostDog98 commented on July 19, 2024

Next opencv-python release will include Qt5 instead of Qt4. That change will most likely solve this issue.

What do we do if we are still having this issue? (version 4.6)

from opencv-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.