forked from a-matsoukas/ground_truth_calculation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarkerless_shadow.py
67 lines (49 loc) · 2.21 KB
/
markerless_shadow.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import numpy as np
import math
from data_processing import load_data, fix_car_bounds, plot_data
def main(markerless_csv_path):
hondafile = markerless_csv_path
eye_point, car_points, nvp_points = load_data(hondafile)
processed_car_points = fix_car_bounds(car_points, nvp_points)
num_nvp_points = np.shape(nvp_points)[0]
nvp_area = 0
for i in range(num_nvp_points - 1):
left_dist = get_distance(eye_point[0], nvp_points[i])
right_dist = get_distance(eye_point[0], nvp_points[i+1])
between_dist = get_distance(nvp_points[i], nvp_points[i+1])
triangle_area = get_area(left_dist, right_dist, between_dist)
nvp_area += triangle_area
print(nvp_area) # square inches
num_processed_car_points = np.shape(processed_car_points)[0]
car_area = 0
for i in range(num_processed_car_points - 1):
left_dist = get_distance(eye_point[0], processed_car_points[i])
right_dist = get_distance(eye_point[0], processed_car_points[i+1])
between_dist = get_distance(processed_car_points[i], processed_car_points[i+1])
triangle_area = get_area(left_dist, right_dist, between_dist)
car_area += triangle_area
print(car_area) # square inches
shadow_area = nvp_area - car_area
print(f"Shadow Area: {shadow_area} sq. in.")
plot_data(eye_point, processed_car_points, nvp_points)
def get_distance(point1, point2):
"""
Calculate cartesian distance between two points
Args:
point1, point2: 1D numpy arrays of length 2, x and y coordinates (in inches)
Returns:
A float representing the distance between the points (in inches)
"""
return math.sqrt((point1[0] - point2[0])**2 + (point1[1] - point2[1])**2)
def get_area(side1, side2, side3):
"""
Calculate the area of a triangle using Heron's forumla
Args:
side1, side2, side3: Floats representing the side lengths of a triangle (in inches)
Returns:
A float representing the area of the triangle (in square inches)
"""
semiperimeter = (side1 + side2 + side3) / 2
return math.sqrt((semiperimeter) * (semiperimeter - side1) * (semiperimeter - side2) * (semiperimeter - side3))
if __name__=="__main__":
main()