Search code examples
pythonopencvimage-processingyolo

detect objects in only specific region of the frame-yolo-opencv


I am counting the total no. of vehicles in a video, but I want to detect only the vehicles which are travelling up(roads have a divider) so my point is, Can i use yolo only on a rectangle where vehicles are moving up? I dont want to detect vehicles that are on the other side of the road.

is there a way like i can draw a rectangle and only detect objects on that specific rectangle?

The best I can think of is for every frame, i'll have to crop the frame, perform all the operations and stitch it back to the original frame. I am expecting an easier alternative for the same

Any help is appreciated. Thanks


Solution

  • You can perform yolo on the entire image as usual, but add an if condition to only draw boxes the center of which falls in a specific region. Or you can add this condition (position) next to the conditions of IoU (where detected boxes are filtered). Also you can separate counting based on the direction of moving vehicles and use two different counters for the two directions.

    If you don't mind me asking, how are you tracking the vehicles?