Hazmat Part 2: Isolating the Interest

Hi, it’s Anthony again.

I’m here to make an addition to the first part of this series, which really belongs in that blog post, but it was getting too long, so I decided to make it into its own. If you haven’t read it, you can read part 1 here:

https://www.sfxrescue.com/developmentupdates/day-195-hazmat-part-1-detecting-the-danger/

After a contour has been detected, it needs to be sliced out of the original image and stored in a separate variable before it can be classified. This is done using numpy’s array region functionality.

We need to iterate over each point in the contour, and find the smallest and largest x and y coordinates so that we can find this bounding box, as in the image above. Then, we can use the numpy array syntax for taking a slice of an array, arr[x1:x2, y1:y2], which equals a new image with upper left coords (x1,y1) and lower right coords (x2,y2). This can be done with the following code:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.