Skip to content

Commit 5b11ce9

Browse files
update frame scaling in distance calculation
1 parent fff868a commit 5b11ce9

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

detect.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ def get_distance(id, b):
116116
dpw = math.hypot(b.xmax - b.xmin, b.ymax - b.ymin) * frame_width
117117
x_dist = y_dist = 0
118118
if id == 0: # cone (labels.txt)
119-
x_dist = cone_diagonal_width * focal_length / dpw
119+
x_dist = cone_diagonal_width * focal_length / dpw / 4
120120
else: # cube (labels.txt)
121-
x_dist = cube_diagonal_width * focal_length / dpw
122-
y_dist = x_dist * math.atan(get_angles(b)[0]) * 180 / math.pi
121+
x_dist = cube_diagonal_width * focal_length / dpw / 4
122+
y_dist = x_dist * math.tan(get_angles(b)[0] * math.pi / 180)
123123
return Point(x_dist, y_dist) # meters
124124

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

349+
if len(results) > 0:
350+
print(results[0])
351+
349352
if cv2.waitKey(1) & 0xFF == ord('q'):
350353
break
351354

0 commit comments

Comments
 (0)