31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
import numpy as np
|
||
from src.distance_estimator import DistanceEstimator
|
||
|
||
def test_distance_estimator():
|
||
# 初始化距离估算器
|
||
focal_length = 35 # mm
|
||
sensor_height = 24 # mm
|
||
avg_person_height = 1700 # mm
|
||
|
||
estimator = DistanceEstimator(
|
||
focal_length=focal_length,
|
||
sensor_height=sensor_height,
|
||
avg_person_height=avg_person_height
|
||
)
|
||
|
||
print("测试距离估算...")
|
||
|
||
# 测试场景1:人物占据画面一半高度
|
||
frame_height = 1080
|
||
person_height_pixels = frame_height / 2
|
||
distance = estimator.estimate_distance(person_height_pixels, frame_height)
|
||
print(f"场景1 - 人物占据画面一半高度时的估算距离: {distance:.2f}mm")
|
||
assert distance > 0, "距离估算结果应该大于0"
|
||
|
||
# 测试场景2:人物占据画面四分之一高度
|
||
person_height_pixels = frame_height / 4
|
||
distance = estimator.estimate_distance(person_height_pixels, frame_height)
|
||
print(f"场景2 - 人物占据画面四分之一高度时的估算距离: {distance:.2f}mm")
|
||
assert distance > 0, "距离估算结果应该大于0"
|
||
|
||
print("距离估算测试完成!") |