Code: Select all
focal_length_px = 8000/4.8 #Focal length(px): 8mm / (4.8 µm / px) = 1667px =: f
Object :
real_obj_width = 0.0373 # Width: 0.0373m
distance = 4 # Distance: 4m
obj_width_px = (object_reall_width/distance) * focal_length_px # Projection of object(px): (0.0373 m / 4 m) * focal_length_px = 15.5 px
< /code>
Nach Objekterkennung möchte ich den Abstand berechnen. Ich habe den Code distance_finder ()
Code: Select all
def distance_finder(focal_length, real_obj_width, obj_width_in_frame):
distance = (real_obj_width * focal_length) / obj_width_in_frame
return distance
< /code>
Und die Ausgabe ist: < /p>
obj_width_in_frame = 17
obj_dst = distance_finder(focal_length_px, obj_width_px, obj_width_in_frame) # obj_dst = 1523.6928104575165