如何在没有校准的情况下获得跟踪对象的速度?



我正在使用YoloV4和Deepsort来检测和跟踪帧中的人。

我的目标是在没有校准的情况下以有意义的单位获得移动的人的速度,因为我希望能够将这个模型的相机移动到不同的房间,而不必每次都校准它。我知道这是一个非常困难的问题。我现在得到的速度是像素每秒。但这是不准确的,因为靠近框架的物体是在"移动"的。更快。

我的问题是,如果我可以使用人检测的边界框作为一个人的像素大小的测量,如果我可以平均一个人的大小(比如68英寸高,15英寸宽),并有必要的"校准";以英寸/秒为单位来确定物体在画面中从A点移动到B点,作为从A区移动到B区的人的尺寸的反映?

简而言之,有没有一种方法可以从物体的大小来确定它在一个帧中的移动速度?

任何建议都会很有帮助的!谢谢!这是我现在计算速度的方法。


# # Calculate the center of the bounding box
xCenter = int((bbox[0] + bbox[2]) / 2)
yCenter = int((bbox[1] + bbox[3]) / 2)
# Get metrics from metrics {track_id : [[frames, xCenter, yCenter], [frames, xCenter, yCenter]] }
values = metrics[track_id]
# # calculate displacement, velocity and speed.
if len(values) > 1:
delta_frames = values[-1][0] - values[-2][0]
delta_t = delta_frames / fps     #fps = 30
delta_x = values[-1][1] - values[-2][1]
delta_y = values[-1][2] - values[-2][2]
total_displacement = math.sqrt(delta_x ** 2 + delta_y ** 2)
speed = total_displacement / delta_t

我想这就是我一直在寻找的答案。

计算边界框的高度和宽度。通过除以人类的平均身高和宽度,我得到了这个边界框每英寸的像素。然后我将区域A的每英寸像素与区域B的每英寸像素之间的linspace()相加,得到距离。但它不是很准确,所以也许我可以改进一下。

误差主要来自于边界框。从上到下的边界框看起来很好,但从左到右(宽度)就不太好了,因为它考虑到了手臂和腿。我要看看是否可以用人类头部检测作为测量方法。

# # Average human dimensions in inches
avg_person_width = 15
avg_person_height = 65
# # width, Height of the bounding box in pixels
bbox_width = bbox[2] - bbox[0]
bbox_height = bbox[3] - bbox[1]
# Pixels per inch within the bounding box
pixels_per_inch_width = bbox_width / avg_person_width
pixels_per_inch_height = bbox_height / avg_person_height
if track.track_id in metrics:
# append the new number to the existing array at this slot
metrics[track_id].append([frame_idx, xCenter, yCenter, pixels_per_inch_width, pixels_per_inch_height])
else:
# create a new array in this slot
metrics[track_id] = [[frame_idx, xCenter, yCenter, pixels_per_inch_width, pixels_per_inch_height]]
values = metrics[track_id]
# # calculate displacement, velocity and speed.
if len(values) > 1:
if all(values[-1]) and all(values[-2]):
delta_frames = values[-1][0] - values[-2][0]
delta_t = delta_frames / fps
delta_x = values[-1][1] - values[-2][1]
delta_y = values[-1][2] - values[-2][2]
pixels_per_inch_width = values[-1][3]
pixels_per_inch_height = values[-1][4]
pixels_per_inch_width_2 = values[-2][3]
pixels_per_inch_height_2 = values[-2][4]
distance_x = np.linspace(pixels_per_inch_width, pixels_per_inch_width_2, abs(delta_x))
distance_y = np.linspace(pixels_per_inch_height, pixels_per_inch_height_2, abs(delta_y))
total_distance_x = sum(distance_x)
total_distance_y = sum(distance_y)
total_displacement = math.sqrt(total_distance_x ** 2 + total_distance_y ** 2)
# # Inches / second (IPS)
speed_ips = total_displacement / delta_t
'''
conversion: 1 inch per second (in/s) = 0.056818182 mile per hour (mph)
'''
# # Miles / Hour. Average human walks at < 3 mph
speed_mph = speed_ips * 0.056818182

最新更新