模块“cv2.cv2"没有属性“ximgproc" [英] Module 'cv2.cv2' has no attribute 'ximgproc'

查看:267
本文介绍了模块“cv2.cv2"没有属性“ximgproc"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 OpenCV 对图像执行选择性搜索,但是当我运行我的代码时,我得到了这个:

<预><代码>>>>导入 cv2>>>ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()回溯(最近一次调用最后一次):文件<stdin>",第 1 行,在 <module> 中AttributeError: 模块 'cv2.cv2' 没有属性 'ximgproc'

我见过类似的问题,但人们通过安装 opencv-contrib-python 包解决了这些问题.我已经安装了这个模块,但问题仍然存在.

这是我的需求文件:

opencv-contrib-python==4.1.0.25opencv-python==4.1.0.25

我使用的是带有 python 3.7 的 conda 环境

解决方案

如 OpenCV pypi 网页中所述:

  1. 如果您安装了以前版本的 OpenCV,请在安装之前删除它以避免冲突.
  2. 有 4 个不同的 opencv 包:opencv-pythonopencv-contrib-pythonopencv-python-headless, opencv-contrib-python-headless.
  3. 您只能安装一个.多个 opencv 包不兼容.

问我的问题时,我有 2 个 opencv 包.因此我首先删除了两个现有的包:

$ pip 卸载 opencv-contrib-python opencv-python

然后,我只安装了一个包:

$ pip install opencv-contrib-python

最后,安装成功了.

I am trying to perform a selective search to an image using OpenCV but when I run my code I get this:

>>> import cv2
>>> ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cv2.cv2' has no attribute 'ximgproc'

I've seen similar problems but people solved them installing opencv-contrib-python package. I've already installed this module but the problem persists.

Here is my requirements file:

opencv-contrib-python==4.1.0.25
opencv-python==4.1.0.25

I am using a conda environment with python 3.7

解决方案

As mentioned in the OpenCV pypi web page:

  1. If you have previous version of OpenCV installed remove it before installation to avoid conflicts.
  2. There are 4 different opencv packages: opencv-python, opencv-contrib-python, opencv-python-headless, opencv-contrib-python-headless.
  3. You can only install one. Multiple opencv packages are incompatible.

When asking my question, I had 2 opencv packages. Therefore I first removed the two existing packages:

$ pip uninstall opencv-contrib-python opencv-python

And then, I installed only one package:

$ pip install opencv-contrib-python

Finally, the installation worked.

这篇关于模块“cv2.cv2"没有属性“ximgproc"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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