Skip to content

Commit

Permalink
update frame scaling in distance calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
Arbitrary-2912 committed Apr 6, 2023
1 parent fff868a commit 5b11ce9
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def get_distance(id, b):
dpw = math.hypot(b.xmax - b.xmin, b.ymax - b.ymin) * frame_width
x_dist = y_dist = 0
if id == 0: # cone (labels.txt)
x_dist = cone_diagonal_width * focal_length / dpw
x_dist = cone_diagonal_width * focal_length / dpw / 4
else: # cube (labels.txt)
x_dist = cube_diagonal_width * focal_length / dpw
y_dist = x_dist * math.atan(get_angles(b)[0]) * 180 / math.pi
x_dist = cube_diagonal_width * focal_length / dpw / 4
y_dist = x_dist * math.tan(get_angles(b)[0] * math.pi / 180)
return Point(x_dist, y_dist) # meters

def make(i):
Expand Down Expand Up @@ -346,6 +346,9 @@ def main():
results = detect_objects(interpreter, image)
cv2_im = overlay_text_detection(results, labels, cv2_im, fps) # (comment out to speed up processing)

if len(results) > 0:
print(results[0])

if cv2.waitKey(1) & 0xFF == ord('q'):
break

Expand Down

0 comments on commit 5b11ce9

Please sign in to comment.