这是最基本的计划:
import numpy
import cv2
img = cv2.imread('watch.jpg', cv2.IMREAD_GRAYSCALE)
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
当我写python3 opencv.py
时,会发生以下错误:
QObject::moveToThread: Current thread (0x2e43c30) is not the object's thread (0x2ee1060).
Cannot move to target thread (0x2e43c30)
Segmentation fault (core dumped)
由于包含imshow()
的行而产生错误。
使用matplotlib
进行绘图效果很好。
使用python2也会产生同样的错误。
我使用以下方法安装/重新安装了opencv:
sudo pip3 install opencv-python
sudo apt install python-opencv
尝试在搜索解决方案时安装contrib包
sudo pip3 install opencv-contrib-python
尝试了两个不同的虚拟环境,即conda
和venv
(显然它没有解决问题)
这是使用gdb python3
>进行调试的结果run opencv.py
Starting program: /home/subtleseeker/virtualenvironment/pp/bin/python3 openCV.py
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff3bac700 (LWP 13322)]
[New Thread 0x7ffff33ab700 (LWP 13323)]
[New Thread 0x7fffeebaa700 (LWP 13324)]
QObject::moveToThread: Current thread (0xee9360) is not the object's thread (0xf867a0).
Cannot move to target thread (0xee9360)
Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
0x00007fffe24d41ce in xcb_send_request_with_fds64 ()
from /usr/lib/x86_64-linux-gnu/libxcb.so.1
我正在使用Kubuntu 17.04。我真的没有选择,还有什么可以尝试。非常感谢任何帮助。