How to fix the error “QObject::moveToThread:” in opencv in python?

前端 未结 15 2123
栀梦
栀梦 2020-12-10 11:18

I am using opencv2 in python with the code

import cv2
cv2.namedWindow(\"output\", cv2.WINDOW_NORMAL)       
cv2.imshow(\"output\",im)
cv2.resizeWindow(\'outp         


        
相关标签:
15条回答
  • 2020-12-10 12:00

    The answer of @Mateen works great if you have Ubuntu version 17 and above. For Ubuntu 16, it's better to compile from sources your opencv python. As @Varun mentioned, follow the opencv tutorial. However, to successfully compile opencv with python 3 I have to add some flags in cmake command:

    cmake -DCMAKE_BUILD_TYPE=RELEASE -DPYTHON_DEFAULT_EXECUTABLE=$(which python3) -DPYTHON_INCLUDE_DIR2=/usr/include/x86_64-linux-gnu/python3.5m/ -DPYTHON3_NUMPY_INCLUDE_DIRS=/usr/local/lib/python3.5/dist-packages/numpy/core/include/ ..

    Hope that will be helpful.

    0 讨论(0)
  • 2020-12-10 12:01

    This may be caused by conflicting installations of Qt libraries. The following command fixed it for me:

    sudo apt-get remove libqt5x11extras5 libqt5x11extras5-dev

    0 讨论(0)
  • 2020-12-10 12:06

    I got same problem, it was from opencv-python version problem for me.
    My Linux machine's environment is as following:

    $ cat /etc/lsb-release 
    ...
    DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
    $ date
    Tue Aug 11 11:43:16 KST 2020
    $ python --version
    Python 3.7.8
    $ pip list|grep Qt
    PyQt5                5.15.0
    PyQt5-sip            12.8.0
    $ pip list|grep opencv-python
    opencv-python        4.3.0.38
    

    I downgraded opencv-python 4.3.0.38 to 4.3.0.36.

    $ pip uninstall opencv-python
    $ pip install opencv-python==4.3.0.36
    $ pip list|grep opencv-python
    opencv-python        4.3.0.36
    
    0 讨论(0)
  • 2020-12-10 12:06

    I don't know why, but installation of matplotlib solved for me the problem with the error

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

    I emphasize that I prepared fresh conda environment where matplotlib was installed. Opencv was installed by pip in conda env as follow pip install opencv-python opencv-contrib-python.

    0 讨论(0)
  • 2020-12-10 12:07

    I tried the above mentioned method and could get opencv module working for my project which uses python3.x interpreter.

    After performing few experiments, i got it working by doing the below steps:

    1) Install opencv-python in your machine using:

    sudo pip3 install opencv-python
    

    2) On the python3.x terminal find the version:

    >>> import cv2
    >>> cv2.__version__
    '3.4.1'
    

    3) Get the same version of OpenCV from their official page.

    4) Perform the CMake settings as mentioned in opencv tutorial. Note the location specified in PYTHON3_PACKAGES_PATH

    5) Once build has been performed, got to the install location specified in PYTHON3_PACKAGES_PATH. Move the library named cv2.cpython-*-gnu.so to the current python3.x dist-packages path:

    usr/local/lib/python3.5/dist-packages/cv2
    

    6) Reload your python3 project and try again!

    0 讨论(0)
  • 2020-12-10 12:07

    I had the same problem when i tried to run a detectron2 demo. My OS is Centos7 and i uninstall some applications about qt.

    find applications about qt.

    yum list installed |grep qt
    

    remove applications

    yum -y remove xxx...
    
    0 讨论(0)
提交回复
热议问题