python中的轨迹交点

时间:2019-03-08 18:28:21

标签: python math computer-vision

我正在使用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")

0 个答案:

没有答案