user3420761
user3420761

Reputation: 41

iOS detect color inside UIImage and crop

I'm trying to figure out the best way to approach this. I'm looking to take an UIImage, detect if there are any shapes/blobs of a specific RGB color, find their frame and crop them into their own image. I've seen a few posts of people recommending OpenCV as well as other links similar to this - Link

Here are 2 screenshot's of what I'm looking to do. So in Example 1 there is the light blue rectangle with some text inside it. I need to detect the blue background and crop the image along the black lines. Same for the red image below it. This is just showing that it doesn't matter what's inside of the color blob. Example 2 shows the actual images that will be cropped once the 2 color blobs are found and cropped. All image will always be on a white background.

Example 1 Example 2

Upvotes: 1

Views: 1976

Answers (1)

Mark McCorkle
Mark McCorkle

Reputation: 9414

This question goes way beyond a simple answer. What you will need to do is access the raw data on that image based on the color then create a frame to crop. I would find the upper, left,right, lower frame of all matches of that specific color then make a frame out of it to crop the image.

Access the color Get Pixel color of UIImage

Crop the image Cropping an UIImage

Upvotes: 1

Related Questions