【錯誤解決】運行cv2.imshow() 時,顯示QObject::moveToThread: Cannot move to target thread等

在服務器上跑如下代碼時:

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

即可解決。

參考:https://github.com/skvark/opencv-python/issues/46

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章