KingPolygon
KingPolygon

Reputation: 4755

iOS: Drawing a Bounding Box Around Non Transparent Pixels In Image?

Say I have an image with a transparent background such as the following:

enter image description here

How can I get the bounding rect for each object and not just one big one?

enter image description here

I'm currently using this category to trim the whitespace out. But I'm not sure how to make it separate objects from each other so they each have their own bounding box, or set a minimum threshold so it doesn't pick up anything smaller than say 16x16 if it's by itself.

Upvotes: 1

Views: 593

Answers (1)

HuaTham
HuaTham

Reputation: 7596

This is a classic problem in computer vision called connected component labeling. The algorithm is not difficult to implement yourself. There are also third-party implementations out there like this (Swift), and this (Objective-C), and OpenCV definitely has this feature available.

Upvotes: 1

Related Questions