MATLAB Answers

Yin Lok
0

Counting bounding boxes inside ROI

Asked by Yin Lok
on 21 Mar 2014
Latest activity Commented on by Andre
on 21 Aug 2016 at 8:27

Hi all, I am currently working on a project on vehicle detection. One of my goal of this project is to count the number of car inside ROI such a lane. the method I think of is to using the centroid of the bounding box to see if it is inside the ROI. but I haven't got a clue on how to start. Since the ROI is a polygon and the centroid is a x,y coordinate, how to know if it has leave the ROI?

  0 Comments

2 Answers

Answer by Image Analyst
on 23 Mar 2014
 Accepted answer

Yin Lok, if you're tracking - something like on this page - then you have one ROI per tracked/detected object. If so you know how many objects there are . If you have multiple ROIs and some of those ROIs have multiple vehicles inside them, then post your image.

  2 Comments

If you have multiple lanes and you have, say, 3 boxes in the left lane, and 5 boxes/cars in the right lane, then if you have polygon coordinates that define each lane, and you have the middle of each box, you can simply use inpolygon to determine if a box middle is inside a lane ROI polygon.

Andre
on 21 Aug 2016 at 8:27

The link goes to features of Computer Vision System Toolbox. Which example there are you referring to?


Answer by Joseph Cheng
on 21 Mar 2014

There are many ways to do this but it depends on how you are defining or receiving the ROI. Is the ROI defined by its corners such that you get 3+ (x,y) points and anything within the triangle to polygon is the ROI? If so it is like if i give you 3+ "y=mx+b" lines and ask if the point is above or below each line. If the ROI is just a mask of zeros and ones then you can just check the (x,y) location in the mask.

  2 Comments

Yin Lok
on 23 Mar 2014

Thanks Joseph, my ROI is defined as a binary mask so i just need to just the x,y coordinates in ones?

Sorry for the late reply, I've been thinking about it more and using the information in your latest comment, you can use the binary mask to get rid of the image outside of your ROI. Then if you are doing anything like the bottom example in the link Image Analyst supplied, you can probably put a minimum size threshold for the vehicle size and remove that tracked vehicle as it leaves the ROI.


Join the 15-year community celebration.

Play games and win prizes!

Learn more
Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!