|
|
|
|
|
|
|
import logging |
|
logging.basicConfig( |
|
level=logging.DEBUG, |
|
format="%(asctime)s - %(levelname)s - %(message)s", |
|
filename="logs.log", |
|
) |
|
|
|
|
|
logger = logging.getLogger("pipline") |
|
|
|
|
|
PERSON_HEIGHT = 1.5 |
|
VEHICAL_HEIGHT = 1.35 |
|
ANIMAL_HEIGHT = 0.6 |
|
FOCAL_LENGTH = 6400 |
|
|
|
def get_distances(merged_boundary_boxes): |
|
"""get distance of object fro image |
|
|
|
Args: |
|
merged_boundary_boxes (json array): takes json array of detected image's data |
|
|
|
Returns: |
|
distance_list: list of distances of each object |
|
""" |
|
logger.info("get_distances function is called...") |
|
|
|
try: |
|
distance_list = [] |
|
for box in merged_boundary_boxes: |
|
for actual_box in box['actual_boundries']: |
|
height = actual_box['bottom_right'][1] - actual_box['top_left'][1] |
|
|
|
if actual_box['class'] == "person": |
|
distance = FOCAL_LENGTH*PERSON_HEIGHT/height |
|
|
|
elif actual_box['class'] == "vehical": |
|
distance = FOCAL_LENGTH*PERSON_HEIGHT/height |
|
|
|
else: |
|
distance = FOCAL_LENGTH*PERSON_HEIGHT/height |
|
|
|
distance_list.append(str(round(distance)) + "m") |
|
return distance_list |
|
except Exception as e: |
|
logger.error("Something went wrong in distance estimation function...") |
|
logger.error(e) |
|
|
|
|