确定碰撞时间

时间:2019-03-10 16:21:39

标签: python algorithm math computer-vision

我正在计算行人和车辆的轨迹。 我想知道计算碰撞时间的算法或做到这一点的算法。

enter image description here

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)

0 个答案:

没有答案