You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using cv.boundingRect to find the bounding rectangle of a uint8 mask image (all 0 or 255) works in the vast majority of situations for me but returns the wrong values for some specific combinations.
Steps to reproduce
import numpy as np
import cv2 as cv
for img_w in range(3, 20):
for img_h in range(1, 15):
img = np.zeros((img_h, img_w), np.uint8)
img[-1, :3] = 255
x, y, w, h = cv.boundingRect(img)
if w != 3:
print(f"{img_w}x{img_h}: {w=}")
boundingRect should return w as 3 for all these combinations of img_w and img_h. But several combinations return w as 1. The other values (x, y, h) seem to be correct.
is because the white pixel at the bottom of the image is not connected to any other white pixels
@iknothing In all of those images generated in the code I posted there are 3 white pixels in a row, all connected, extending right from the bottom right corner. There is never a single pixel by itself.
System Information
opencv-python-headless: 4.8.0.76
OS: MacOS 13.5.1
Python: 3.11.4
Detailed description
Using
cv.boundingRect
to find the bounding rectangle of a uint8 mask image (all 0 or 255) works in the vast majority of situations for me but returns the wrong values for some specific combinations.Steps to reproduce
boundingRect
should returnw
as 3 for all these combinations ofimg_w
andimg_h
. But several combinations returnw
as1
. The other values (x
,y
,h
) seem to be correct.Issue submission checklist
The text was updated successfully, but these errors were encountered: