How to create Axis-aligned bounding boxes using Flatten()

asked 2020-02-19 00:53:19 -0600

Samiha gravatar image

updated 2020-02-20 00:16:46 -0600

berak gravatar image

I am trying to get axis-aligned bounding box where the original algorithm used rotated bounding boxes. corresponding lines are --

if len(contours) != 0 and np.max(cnt_area) > 100:
        contour = contours[np.argmax(cnt_area)]  # use max area polygon
        polygon = contour.reshape(-1, 2)
        pbox = cv2.boundingRect(polygon)  # Min Max Rectangle
        #pbox = cv2.boxPoints(cv2.minAreaRect(polygon))
        box_in_img = pbox
        state['ploygon'] = rbox_in_img if mask_enable else []

location = state['ploygon'].flatten()

But getting the following error: tuple object doesnot have flatten. but flatten() previously worked with rotated bounding boxes. If I remove flatten to execute the code, the error is gone but I am getting wrong bounding boxes like this--

image description Please give some ideas to solve this issue.

edit retag flag offensive close merge delete

Comments

please put more code into your question, noone will parse a whole github repo to understand your problem

berak gravatar imageberak ( 2020-02-19 05:02:18 -0600 )edit

state['ploygon'] = rbox_in_img if mask_enable else []

please check:

  • type(state['ploygon']) (probably not a numpy array, so flatten() cannot be applied)
  • mask_enable (if False, you get an empty list)
  • is ploygon the correct key ? (looks like a typo)
berak gravatar imageberak ( 2020-02-20 01:33:24 -0600 )edit