I think you can use the following. I tried it - it s working
import cv2, random
image = cv2.imread("x.jpg")
ss = cv2.ximgproc.segmentation.createSelectiveSearchSegmentation()
ss.setBaseImage(image)
ss.switchToSelectiveSearchQuality()
rects = ss.process()
for i in range(0, len(rects), 100):
# clone the original image so we can draw on it
output = image.copy()
# loop over the current subset of region proposals
for (x, y, w, h) in rects[i:i + 100]:
# draw the region proposal bounding box on the image
color = [random.randint(0, 255) for j in range(0, 3)]
cv2.rectangle(output, (x, y), (x + w, y + h), color, 2)
cv2.imshow("Output", output)
key = cv2.waitKey(0) & 0xFF
# if the `q` key was pressed, break from the loop
if key == ord("q"):
break
Why 100? I chose a chunk size of 100.
Original Image:
After processing: