I am trying to find a method to calculate the velocity and acceleration of a tracked object, lets say a ball falling. I am using Processing 2 to make this program, and I know the distance from the camera to the object and it can calculate its position in every frame during the motion.
To calculate the velocity, I used this formula (all calculated in pixels): VelocityX=(PositionX - LastPositionX)/delta time
And something similar with acceleration: AccelerationX=(VelocityX - LastVelocityX)/delta time
Then, I changed delta time with frames. So now I have velocity and acceleration in Pixels per frame, but my question is how can I transform this Pixels per frame unit to mm/s for example? to more intuitive units like that.
I calculate the position in pixels too, but I make a conversion to mm after that, but I'm a little confused about how to do that for velocity and acceleration.
// Get the current time
currTime = frameCount;
deltaTime = (currTime - prevTime);
// Remember current time for the next frame
prevTime = currTime;
// Calculate velocity in X and Y directions (pixels / frame)
if (lastMovingX != Float.MAX_VALUE) {
velX = (PX - lastMovingX) / deltaTime;
velY = (PY - lastMovingY) / deltaTime;
}
// Save the current frame position for the next calculation
lastMovingX = PX;
lastMovingY = PY;
if (lastVelX != Float.MAX_VALUE) {
accelX = (velX - lastVelX) / deltaTime;
accelY = (velY - lastVelY) / deltaTime;
}
lastVelX = velX;
lastVelY = velY;
If you know the size of the object, you can extract the ratio of pixels/mm. If you know your frame rate, you can convert frames to seconds.
To find pixels/mm = Object size in pixels / object size in mm
(pixels/frame) / (pixels/mm) = mm/frame
mm/frame * frames/second = mm / second
Is this what you are looking for?