我正在使用tensorflow和python检测人员和车辆。我计算轨迹并使用卡尔曼滤波器预测它们,然后我拟合一条直线来预测轨迹。
我的问题是如何找到两个轨迹之间的交叉点和碰撞时间?
我试着线到线的交点,但拟合的线并不总是两点线,它是折线。这是我的尝试:
detections = tracker.update(np.array(z_box))
for trk in detections[0]:
trk = trk.astype(np.int32)
helpers.draw_box_label(img, trk, trk[4]) # Draw the bounding boxes on the
centerCoord = (((trk[1] +trk[3]) / 2), (trk[0] + trk[2]) / 2)
point_lists[trk[4]].append(centerCoord)
x = [i[0] for i in point_lists[trk[4]]]
y = [i[1] for i in point_lists[trk[4]]]
p = np.polyfit(x, y, deg=1)
y = p[1] + p[0] * np.array(x)
fitted = list(zip(x, y))
cv2.polylines(img, np.int32([fitted]), False, color=(255, 0, 0))
for other in detections[0]:
other = other.astype(np.int32)
if other[4] != trk[4]: # check for self ID
x2 = [i[0] for i in point_lists[other[4]]]
y2 = [i[1] for i in point_lists[other[4]]]
p2 = np.polyfit(x2, y2, deg=1)
y2 = p2[1] + p2[0] * np.array(x2)
other_fitted = list(zip(x2, y2))
if(line_intersection(fitted, other_fitted)):
print("intersection")
else:
print("not intersection")
发布于 2019-03-13 04:05:50
这是一个更广泛的话题,所以我将只关注数学/物理部分,因为我感觉CV/DIP部分已经由你们两个提问者(andre ahmed和chris burgees)处理了。
为了简单起见,我假设线性运动速度恒定,因此如何做到这一点:
在已知时间
dt
之后,每个对象的2个独立帧的 2D位置因此,在3D中获取每个对象在图像上的2D中心(或角或其他)位置,并将其转换为3D
因此,使用已知的摄像机参数或关于场景的已知背景信息,您可以将屏幕上的2D位置反投影为相对于摄像机的3D相对位置。如果像2D情况一样处理,这将消除其他需要的非线性插值。
有更多的选择如何获得3D位置取决于你得到了什么在你的处置。例如:
- [Transformation of 3D objects related to vanishing points and horizon line](https://stackoverflow.com/a/53303948/2521214)
速度向量很简单:
vel =( pos(t+dt) - pos(t) )/dt
因此,简单地从2个后续帧中减去相同对象的位置,并除以帧速率周期(或者帧之间的间隔,对于每个2个对象的碰撞
这是一个有趣的东西是的,你可以解决一个不等式系统,比如:
|( pos0 + vel0 *t)- (pos1 + vel1 *t)| <=阈值
但我在这里使用了一种更简单的方法
- [Collision detection between 2 “linearly” moving objects in WGS84](https://stackoverflow.com/a/41123777/2521214)
这个想法是在测试对象最接近的地方计算t
(如果接近彼此)。
所以我们可以像这样推断每个物体的未来位置:
位置(T)=位置(T0)+速度*(t-t0)
其中t
是实际时间,t0
是某个开始时间(例如t0=0
)。
假设我们有两个对象(pos0,vel0,pos1,vel1
),我们想要测试,所以计算它们距离的前两次迭代,这样:
pos0(0) = pos0;pos1(0) = pos1;dis0 =| pos1(0) - pos0(0) | pos0(dt) = pos0 + vel0*dt;pos1(dt) = pos1 + vel1*dt;dis1 =| pos1(dt) - pos0(dt) |
其中dt
是一些足够小的时间(以避免跳过冲突)。现在,对象正在修剪,所以没有碰撞,对象不会相互移动或平行移动,只有if (dis0>dis1)
对象彼此靠近,所以我们可以估计:
dis(t) = dis0 + (dis1-dis0)*t
碰撞期望dis(t)=0
,所以我们可以再次外推:
0= dis0 + (dis1- dis0 )*t ( dis0 -dis1)*t =dis0 t=dis0/ (dis0-dis1)
其中t
是估计的冲突时间。粗略的所有这些处理所有的运动都是线性的,并且外推了很多,所以它不准确,但是你可以对更多的后续帧这样做,随着时间接近碰撞,结果将会更准确。此外,为了确保你应该外推每个物体在估计碰撞时的位置,以验证结果(如果没有碰撞,那么外推只是数字,物体没有碰撞,只是在一段时间内接近每个物体)
正如前面提到的,转换为3D (bullet #2)并不是必需的,但它消除了非线性,因此简单的线性插值/外推可以在以后使用,从而大大简化事情。
https://stackoverflow.com/questions/55068993
复制相似问题