Subh775 commited on
Commit
e0a36dd
·
1 Parent(s): 5cd1866

processing speed enhancements

Browse files
backend/engine.py CHANGED
@@ -180,11 +180,11 @@ def run(model, video_path, line, config, on_frame, save_annotated=False, annotat
180
  cur_boxes = xyxy
181
  cur_ids = ids
182
 
183
- for obj_id, c, box in zip(ids, cls, xyxy):
184
  cx = int((box[0] + box[2]) / 2)
185
  cy = int((box[1] + box[3]) / 2)
186
 
187
- heatmap_points.append([cx, cy, float(r.boxes.conf.cpu().numpy()[list(ids).index(obj_id)])])
188
  track_positions[obj_id].append((frame_idx, cx, cy))
189
 
190
  if not valid_line:
 
180
  cur_boxes = xyxy
181
  cur_ids = ids
182
 
183
+ for obj_id, c, box, conf_val in zip(ids, cls, xyxy, confs):
184
  cx = int((box[0] + box[2]) / 2)
185
  cy = int((box[1] + box[3]) / 2)
186
 
187
+ heatmap_points.append([cx, cy, float(conf_val)])
188
  track_positions[obj_id].append((frame_idx, cx, cy))
189
 
190
  if not valid_line:
backend/geometry.py CHANGED
@@ -1,12 +1,17 @@
1
- import numpy as np
 
2
 
3
  def _side(p, a, b):
4
- return np.sign((b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0]))
 
 
5
 
6
  def _point_to_segment_dist(px, py, ax, ay, bx, by):
7
- A = np.array([ax, ay], dtype=float)
8
- B = np.array([bx, by], dtype=float)
9
- P = np.array([px, py], dtype=float)
10
- AB = B - A
11
- t = np.clip(np.dot(P - A, AB) / np.dot(AB, AB), 0, 1)
12
- return np.linalg.norm(P - (A + t * AB))
 
 
 
1
+ import math
2
+
3
 
4
  def _side(p, a, b):
5
+ cross = (b[0] - a[0]) * (p[1] - a[1]) - (b[1] - a[1]) * (p[0] - a[0])
6
+ return (cross > 0) - (cross < 0)
7
+
8
 
9
  def _point_to_segment_dist(px, py, ax, ay, bx, by):
10
+ abx, aby = bx - ax, by - ay
11
+ ab_sq = abx * abx + aby * aby
12
+ if ab_sq == 0:
13
+ return math.hypot(px - ax, py - ay)
14
+ t = max(0.0, min(1.0, ((px - ax) * abx + (py - ay) * aby) / ab_sq))
15
+ proj_x = ax + t * abx
16
+ proj_y = ay + t * aby
17
+ return math.hypot(px - proj_x, py - proj_y)
backend/server.py CHANGED
@@ -469,7 +469,7 @@ async def ws_run(ws: WebSocket):
469
  if done:
470
  break
471
 
472
- await asyncio.sleep(0.05)
473
 
474
  result = task.result() # re-raises any exception from the engine
475
  result["report_format"] = report_format
 
469
  if done:
470
  break
471
 
472
+ await asyncio.sleep(0.02)
473
 
474
  result = task.result() # re-raises any exception from the engine
475
  result["report_format"] = report_format
frontend/js/initial.js CHANGED
@@ -71,7 +71,7 @@ function uploadFile(file) {
71
  // Estimate upload duration: ~1 MB/s conservative, capped between 3s and 60s
72
  const fileMB = file.size / (1024 * 1024);
73
  const estDurationMs = Math.min(Math.max(fileMB * 1000, 3000), 60000);
74
- const targetPct = 98; // stop simulation at 98%, snap to 100% on load
75
  const tickMs = 200; // update every 200ms
76
  const totalTicks = estDurationMs / tickMs;
77
  const stepPerTick = targetPct / totalTicks;
 
71
  // Estimate upload duration: ~1 MB/s conservative, capped between 3s and 60s
72
  const fileMB = file.size / (1024 * 1024);
73
  const estDurationMs = Math.min(Math.max(fileMB * 1000, 3000), 60000);
74
+ const targetPct = 100; // stop simulation at 100%
75
  const tickMs = 200; // update every 200ms
76
  const totalTicks = estDurationMs / tickMs;
77
  const stepPerTick = targetPct / totalTicks;
frontend/js/vehicles.js CHANGED
@@ -1169,7 +1169,7 @@ window.switchTab = switchTab;
1169
  }
1170
 
1171
  const now = performance.now();
1172
- if (now - lastUIUpdate < 300) return;
1173
  lastUIUpdate = now;
1174
 
1175
  updateCongestion(liveCongestion, stride);
 
1169
  }
1170
 
1171
  const now = performance.now();
1172
+ if (now - lastUIUpdate < 150) return;
1173
  lastUIUpdate = now;
1174
 
1175
  updateCongestion(liveCongestion, stride);