Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

To get a moving object's speed as single scalar value #292

Open
armine105 opened this issue Feb 1, 2024 · 1 comment
Open

To get a moving object's speed as single scalar value #292

armine105 opened this issue Feb 1, 2024 · 1 comment
Labels
help wanted Extra attention is needed

Comments

@armine105
Copy link

armine105 commented Feb 1, 2024

Hello
How are you?
Thanks for contributing to this project.
I want to get a moving object's speed as single scalar value.
I see there is a velocity member in a tracked object.
But it is a 2x2-D array as vector.

[
[39.56255496 -1.89730458]
[40.79390178 -1.70833893]
]
Of course, I used object bounding boxes as tracking module's input.
How can I get an object's moving speed as single scalar value

@armine105 armine105 added the help wanted Extra attention is needed label Feb 1, 2024
@aguscas
Copy link
Collaborator

aguscas commented Feb 1, 2024

Hello! The TrackedObject.estimate_velocity is returning the horizontal and vertical velocity for each keypoint (in your case, for each corner of the bounding box) of your tracked object. If you want to give a single number, you should first average the velocities of both corners, and then take the norm of that final vector.

Here is an example of how to do that for a TrackedObject instance named obj:

import numpy as np

np.linalg.norm(obj.estimate_velocity.mean(axis=0))

Remember that this velocity is in pixels/frame units (so, how many pixels does the object move between consecutive frames). If you want to know the velocity in real units like meters/second, you will need to know

  • the relationship between a pixel and a meter (which might be different on each axis depending on the perspective and where your object is in the image)
  • the real time difference between consecutive frames in your video (typically is just the inverse of the fps, but if your video was in slow-motion or was a timelapse you would also need to contemplate that).

Once you have that information, you would have to convert the entries of obj.estimate_velocity accordingly before averaging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants