在服务器上跑如下代码时:
import cv2
img = cv2.imread("2.jpg")
b,g,r = cv2.split(img)
cv2.imshow("Blue",r)
会出现下面的error:
QObject::moveToThread: Current thread (0x7f5cf6bbfa0) is not the object's thread (0x1d347b20).
Cannot move to target thread (0x7f5cf6bbfa0)
由于我的是在远程服务器跑,我的服务器是无法将其显示出来的,所以可以用保存图片的函数保存,下载下来看
cv2.imwrite('temp1.jpg', b)
当然,如果在自己主机也无法跑的话,可以参考这个方法:
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 @skvarkmentioned, it's probably due to Qt conflicts.
就是使用如下命令:
sudo apt-get remove libqt5x11extras5
即可解决。