Bamwani
Bamwani

Reputation: 95

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

Upvotes: 0

Views: 4401

Answers (2)

Jack Froster
Jack Froster

Reputation: 79

i'm doing a similar thing...

if your product is going to be fixed on like a light poll then clearly you can either detect the road and zebra crossing by training a model.

or

manually enter these values...

later run your object detection and object tracking on only these parts of the frames i.e, use

frame[ymax:ymin, xmax:xmin]

This reduces the image size so your processing speed increases.

but why do you need the full image again after your work? still if you do need it then you just have to add the values of xmin and ymin of your object detection box on the road to the bounding box of the vehicle detected in that object detection box to get its bounding box values in uncropped image.

Upvotes: 0

Hadi GhahremanNezhad
Hadi GhahremanNezhad

Reputation: 2445

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?

Upvotes: 1

Related Questions