hack direction
Browse files- aimodel.py +7 -2
aimodel.py
CHANGED
@@ -214,7 +214,12 @@ def read_meter(img:Image.Image|str|Path, fl, fl_ft):
|
|
214 |
center = circle_props.centroid[::-1]
|
215 |
|
216 |
# XXX: the needle direction is from center to orign
|
217 |
-
|
|
|
|
|
|
|
|
|
|
|
218 |
direction = -direction
|
219 |
|
220 |
# calculate the needle theta
|
@@ -288,7 +293,7 @@ def more_visualization_data(meter_result:MeterResult):
|
|
288 |
# calculate the needle head(farest point from center)
|
289 |
needle_coordinates = np.concatenate(result.needle_polygons).reshape(-1, 2)
|
290 |
needle_length = np.linalg.norm(needle_coordinates - center,axis=1)
|
291 |
-
farest_idx = np.argmax(needle_length)
|
292 |
needle_head = needle_coordinates[farest_idx]
|
293 |
needle_head_length = needle_length[farest_idx]
|
294 |
direction = meter_result.direction * needle_head_length
|
|
|
214 |
center = circle_props.centroid[::-1]
|
215 |
|
216 |
# XXX: the needle direction is from center to orign
|
217 |
+
# HACK: use needle_head instead of origin compares to center
|
218 |
+
needle_coordinates = np.concatenate(result.needle_polygons).reshape(-1, 2)
|
219 |
+
needle_length = np.linalg.norm(needle_coordinates - center,axis=1)
|
220 |
+
farest_idx = np.argmax(needle_length)
|
221 |
+
needle_head = needle_coordinates[farest_idx]
|
222 |
+
if (needle_head - center) @ direction < 0:
|
223 |
direction = -direction
|
224 |
|
225 |
# calculate the needle theta
|
|
|
293 |
# calculate the needle head(farest point from center)
|
294 |
needle_coordinates = np.concatenate(result.needle_polygons).reshape(-1, 2)
|
295 |
needle_length = np.linalg.norm(needle_coordinates - center,axis=1)
|
296 |
+
farest_idx = np.argmax(needle_length)
|
297 |
needle_head = needle_coordinates[farest_idx]
|
298 |
needle_head_length = needle_length[farest_idx]
|
299 |
direction = meter_result.direction * needle_head_length
|