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

前端 未结 15 2122
栀梦
栀梦 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条回答
  • 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
    
    0 讨论(0)
  • 2020-12-10 11:57

    This problem not present if runing opencv without virtualenviroment. My system: Kbuntu 18.04 LTS GTX 1050 CUDA 9.2 Tensorflow 1.9

    0 讨论(0)
  • 2020-12-10 11:59

    I solved this issue and I posted my solution in related issue on OpenCV github page. But for your convenience, I will post it here also.

    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.

    0 讨论(0)
  • 2020-12-10 11:59

    I fixed this under Ubuntu 18.04 LTS by uninstalling any OpenCV packages from pip and apt and installing OpenCV directly from source. Maybe this tutorial will help:

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

    0 讨论(0)
  • 2020-12-10 11:59

    I followed the solution suggested by @Varun and it worked for me (using Python 3). However, I didn't install the built files, as I do not have the admin rights on the system where I need the cv package. A cmake, followed by make was enough, I then took the cv2.*.gnu file from ../build/lib/python3 folder and replaced the one in the site-packages/cv2 folder of my virtual environment

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

    I know the thread is a bit old but posting for anyone else out there, I faced the same problem and it was because even after running

    pip3 uninstall opencv-python
    

    there was another version of open-cv in my system which I checked by

    pip list
    

    (I'm guessing that pip only removes the first version it finds) So I ran this command again

    pip3 uninstall opencv-python
    

    And now simply installing opencv by

    pip install opencv-python
    

    worked for me.

    0 讨论(0)
提交回复
热议问题