我正在尝试找到一种方法来计算被跟踪对象的速度和加速度,比方说一个落下的球。我正在使用 Processing 2 来制作这个程序,我知道从相机到物体的距离,它可以在运动过程中计算它在每一帧中的位置。
为了计算速度,我使用了这个公式(全部以像素计算):VelocityX=(PositionX - LastPositionX)/delta time
与加速度类似:AccelerationX=(VelocityX - LastVelocityX)/delta time
然后,我用帧改变了增量时间。所以现在我有每帧像素的速度和加速度,但我的问题是如何将每帧像素单位转换为 mm/s?到更直观的单位。
我也以像素为单位计算位置,但之后我将其转换为毫米,但我对如何计算速度和加速度感到有些困惑。
// 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;
最佳答案
如果你知道物体的大小,你可以提取像素/毫米的比率。如果您知道帧速率,则可以将帧转换为秒。
要查找像素/mm = 以像素为单位的对象大小/以毫米为单位的对象大小
(像素/帧)/(像素/毫米)=毫米/帧
毫米/帧 * 帧/秒 = 毫米/秒
这是您要找的吗?
关于opencv - 视频中的速度和加速度测量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30378718/