-
Couldn't load subscription status.
- Fork 5.9k
Description
System information (version)
- OpenCV => 4.1
- Operating System / Platform => Linux Mint 18.1 Serena
- Installed opencv-contrib-python 4.1.0 module from pip
Detailed description
As described in the title, when using opencv in python 3, the Selective Search Segmentation module raises an exception on an image with a width-to-height or height-to-width ratio greater than about 2.43. The exact ratio where the problem starts differs depending on the size of the input image, but is close to 2.4 or 2.5 in every case I've tried.
Steps to reproduce
import cv2
import selectivesearch as ss
import skimage.data
import numpy as np
# image is 300 x 451 x 3
img = skimage.data.chelsea()
cvss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
# this works
cvss.setBaseImage(img)
cvss.switchToSingleStrategy()
single_cvss_results = cvss.process()
# this works too
img = cv2.resize(img, (300, 731))
cvss.setBaseImage(img)
cvss.switchToSingleStrategy()
single_cvss_results = cvss.process()
# this raises an exception when cvss.process() is called!
img = cv2.resize(img, (300, 732))
cvss.setBaseImage(img)
cvss.switchToSingleStrategy()
single_cvss_results = cvss.process()
# any greater h:w ratio will cause the same exception...
img = cv2.resize(img, (300, 1000))
cvss.setBaseImage(img)
cvss.switchToSingleStrategy()
single_cvss_results = cvss.process()
# this works...
img = cv2.resize(img, (30, 79))
cvss.setBaseImage(img)
cvss.switchToSingleStrategy()
single_cvss_results = cvss.process()
# this raises the same exception when cvss.process() is called!
img = cv2.resize(img, (30, 80))
cvss.setBaseImage(img)
cvss.switchToSingleStrategy()
single_cvss_results = cvss.process()The exception raised is:
cv2.error: OpenCV(4.1.0) /io/opencv/modules/core/src/matrix.cpp:466: error: (-215:Assertion failed) 0 <= roi.x && 0 <= roi.width && roi.x + roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height <= m.rows in function 'Mat'
An identical exception is raised if the height and width values in the above code are swapped. The same exception is also raised regardless of whether the single, fast, or quality SS strategy is selected.
I've also been able to replicate this on another system running Ubuntu 16.04, using opencv 3.4.2, and with different input images.
I've cross-posted this on the issues page for the opencv_contrib repo, since I wasn't sure where it belonged.