Python OpenCV错误:当前线程不是对象的线程 [英] Python OpenCV Error: Current thread is not the object's thread

查看:1736
本文介绍了Python OpenCV错误:当前线程不是对象的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用cv2模块运行简单代码时出错.

I'm having an error running simple code using cv2 module.

就这样:

import cv2

img = cv2.imread('sudoku.png',0)

cv2.imshow('image',img)

它失败并显示以下错误:

And it fails with the following error:

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

我搜索了此错误,并尝试了很多方法,但无济于事.我尝试不使用pip进行安装,尝试使用分步安装(来自官方OpenCV),但没有帮助.

I googled this error and tried a lot of things but it doesn't help. I tried installing without pip, I tried using step-by-step installation (from official OpenCV) but nothing helps.

当我跑步时:

cv2.__version__

它返回3.4.3

推荐答案

根据此问题发布在OpenCV GitHub上,这是开发人员指出的几乎无法修复的已知问题.显然,这是由于系统上的任何Qt安装与OpenCV附带的Qt发生冲突而引起的.有一些建议可以从系统中删除libqt5x11extras5软件包.这可能会修复某些问题,但在使用基于Qt的窗口管理器的Linux发行版上运行这些库的任何人,都将通过删除此程序包使它们的桌面环境无法使用(自己尝试过).

According to this issue posted on the OpenCV GitHub, this is a known issue that the developer states is damn near impossible to fix. It is apparently caused by a conflict in any Qt installations on the system with the Qt that is shipped with OpenCV. There are some suggestions floating around to remove the libqt5x11extras5 package from the system. This may fix it for some but anyone running these libraries on a Linux distribution that uses a window manager based on Qt will render their desktop environment unusable by removing this package (having tried it myself).

您可以在运行cmake时尝试使用WITH_GTK=ON选项从源代码构建OpenCV,这将使用GTK而不是Qt,从而避免了冲突.但是,在使用虚拟环境时,很难在Python中使用它.

You can try building OpenCV from source using the WITH_GTK=ON option when running cmake which will use GTK instead of Qt, circumventing the conflict. However, this is hard to make use of in Python when using virtual environments.

这篇关于Python OpenCV错误:当前线程不是对象的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆