LogicLover90
LogicLover90

Reputation: 229

How can I delete the background outside the drawn contours?

How can I delete the background outside the drawn contours? My main goal is measure size of ONLY cardboard boxes. I have 2 differend code.

First code measuring EVERYTHING with aruco marker.

Second code is detecting boxes with yolo.(I need this because measure code detects everything)

Both of them drawn contours.

My measure code is measuring everything thats why i want to remove background except contoured objects.

how can i manage this?

Please help.

enter image description here

Upvotes: 1

Views: 308

Answers (2)

Serhii Maksymenko
Serhii Maksymenko

Reputation: 319

GrabCut algorithm seems like what you need in this case. It will distinguish background and foreground pixels inside a bounding box.

Upvotes: 0

Nuzhny
Nuzhny

Reputation: 1927

Create black mask image. For each detection draw it contour on mask:

cv2.drawContours(img, contours, -1, color=(255, 255, 255), thickness=cv2.FILLED)

And after make bitwise_and with this mask.

Upvotes: 2

Related Questions