Skip to content

AttributeError: module 'cv2' has no attribute 'ximgproc' #829

@nicolaslesquoy

Description

@nicolaslesquoy

Expected behaviour

I didn't expect this error. I checked various forums about this issue, like StackOverflow or this GitHub repo and it seems to be caused by conflicting installation of opencv but I checked and I have only one version of the package installed (opencv-python)

Actual behavior

I receive the following error :

Traceback (most recent call last):
  File "[...]/pattern.py", line 7, in <module>
    ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
AttributeError: module 'cv2' has no attribute 'ximgproc'

Steps to reproduce

  • Run the following file
import cv2

img = cv2.imread("image.jpg")

# Create a Selective Search object
ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()

# Set the input image
ss.setBaseImage(img)

# Run the selective search algorithm
ss.switchToSelectiveSearchFast()
rects = ss.process()

# Show the results
for i, rect in enumerate(rects):
    x, y, w, h = rect
    cv2.rectangle(img, (x, y), (x+w, y+h), (0, 255, 0), 2)

cv2.imshow("Selective Search", img)
cv2.waitKey(0)
  • operating system & architecture : I use Ubuntu 22.04 (x86-64)
  • opencv-python version : opencv_python-4.7.0.72 with Python 3.10.6

I used to following methods to try to mitigate this issue:

  • I uninstalled opencv-python and checked that it was not installed anymore.
  • I purged the download cache of pip
  • I installed opencv-python with pip.
Issue submission checklist
  • This is not a generic OpenCV usage question (looking for help for coding, other usage questions, homework etc.)

  • I have read the README of this repository and understand that this repository provides only an automated build toolchain for OpenCV Python packages (there is no actual OpenCV code here)

  • The issue is related to the build scripts in this repository, to the pre-built binaries or is a feature request (such as "please enable this additional dependency")

  • I'm using the latest version of opencv-python

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions