我正在尝试使用匀称找到两个轨迹之间的交点 但是,在下图中的这种情况下,行人和车辆之间存在虚假的正交点。
这是我在python中的尝试:
for trk in car_detections[0]:
trk = trk.astype(np.int32)
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 ped_detections[0]:
other = other.astype(np.int32)
centerCoord = (((other[1] + other[3]) / 2), (other[0] + other[2]) / 2)
point_lists[other[4]].append(centerCoord)
x2 = [i[0] for i in point_lists[other[4]]]
y2 = [i[1] for i in point_lists[other[4]]]
if x2 and y2:
p2 = np.polyfit(x2, y2, deg=1)
y2 = p2[1] + p2[0] * np.array(x2)
other_fitted = list(zip(x2, y2))
cv2.polylines(img, np.int32([other_fitted]), False, color=(255, 0, 0))
if len(other_fitted) > 2 and len(fitted) > 2:
line1 = LineString(fitted)
line2 = LineString(other_fitted)
if (line1.intersection(line2).is_valid):
font = cv2.FONT_HERSHEY_SIMPLEX
font_size = 0.7
font_color = (255, 0, 0)
print("collision")
cv2.putText(img, "collision between car =>>>"+str(trk[4])+"and ped ==>" +str(other[4]), (0,400), font, font_size, font_color, 1, cv2.LINE_AA)