Shoraky commited on
Commit
70f1014
·
1 Parent(s): 8dc3ee4

Read target size from calibration

Browse files
Files changed (1) hide show
  1. api.py +23 -10
api.py CHANGED
@@ -1805,11 +1805,26 @@ async def save_upload_to_path(upload: UploadFile, destination: str):
1805
  f.write(chunk)
1806
 
1807
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1808
  def run_analysis_job(
1809
  request_base_url: str,
1810
  player_id: str,
1811
- target_w: float,
1812
- target_h: float,
1813
  client_id: str,
1814
  session_id: str,
1815
  session_dir: str,
@@ -1823,6 +1838,7 @@ def run_analysis_job(
1823
 
1824
  try:
1825
  ensure_not_cancelled()
 
1826
 
1827
  set_progress(client_id, 10.0, "Preparing AI Models", status="running", sessionId=session_id)
1828
  runtime = ensure_runtime_ready()
@@ -2150,8 +2166,6 @@ def run_analysis_job(
2150
  async def analyze_endpoint(
2151
  request: Request,
2152
  playerId: str = Form(...),
2153
- targetW: float = Form(...),
2154
- targetH: float = Form(...),
2155
  clientId: str = Form(...),
2156
  videoOrders: List[int] = Form(...),
2157
  actionsJson: UploadFile = File(...),
@@ -2184,6 +2198,7 @@ async def analyze_endpoint(
2184
 
2185
  calib_path = os.path.join(session_dir, "calibration.npz")
2186
  await save_upload_to_path(calibration, calib_path)
 
2187
 
2188
  camera_map = {}
2189
  for idx, (camera_order, video) in enumerate(zip(videoOrders, videos)):
@@ -2209,8 +2224,7 @@ async def analyze_endpoint(
2209
  run_analysis_job,
2210
  request_base_url,
2211
  playerId,
2212
- targetW,
2213
- targetH,
2214
  clientId,
2215
  session_id,
2216
  session_dir,
@@ -2257,8 +2271,6 @@ async def analyze_endpoint(
2257
  async def analyze_endpoint_inline(
2258
  request: Request,
2259
  playerId: str = Form(...),
2260
- targetW: float = Form(...),
2261
- targetH: float = Form(...),
2262
  clientId: str = Form(...),
2263
  videoOrders: List[int] = Form(...),
2264
  actionsJson: UploadFile = File(...),
@@ -2284,6 +2296,7 @@ async def analyze_endpoint_inline(
2284
  calib_path = os.path.join(session_dir, "calibration.npz")
2285
  with open(calib_path, "wb") as f:
2286
  f.write(await calibration.read())
 
2287
 
2288
  if len(videoOrders) != len(videos):
2289
  raise ValueError("Each uploaded video must include a matching camera order")
@@ -2313,7 +2326,7 @@ async def analyze_endpoint_inline(
2313
  }
2314
 
2315
  sizes = {
2316
- "TARGET_SIZE": (int(targetW), int(targetH)),
2317
  "YOLO_IMGSZ": 960
2318
  }
2319
 
@@ -2541,7 +2554,7 @@ async def analyze_endpoint_inline(
2541
  "id": session_id,
2542
  "playerId": playerId,
2543
  "createdAt": int(time.time() * 1000),
2544
- "targetSize": [int(targetW), int(targetH)],
2545
  "cameraCount": len(camera_map),
2546
  "actions": formatted_actions,
2547
  "failedActions": failed_actions
 
1805
  f.write(chunk)
1806
 
1807
 
1808
+ def read_calibration_target_size(calib_path: str):
1809
+ with np.load(calib_path) as data:
1810
+ if "target_size" not in data:
1811
+ raise ValueError("Calibration file must include target_size")
1812
+ target_size = np.asarray(data["target_size"]).astype(float).reshape(-1)
1813
+
1814
+ if target_size.size != 2:
1815
+ raise ValueError("Calibration target_size must contain exactly width and height")
1816
+
1817
+ target_w, target_h = int(target_size[0]), int(target_size[1])
1818
+ if target_w <= 0 or target_h <= 0:
1819
+ raise ValueError("Calibration target_size values must be positive")
1820
+
1821
+ return target_w, target_h
1822
+
1823
+
1824
  def run_analysis_job(
1825
  request_base_url: str,
1826
  player_id: str,
1827
+ target_size,
 
1828
  client_id: str,
1829
  session_id: str,
1830
  session_dir: str,
 
1838
 
1839
  try:
1840
  ensure_not_cancelled()
1841
+ target_w, target_h = target_size
1842
 
1843
  set_progress(client_id, 10.0, "Preparing AI Models", status="running", sessionId=session_id)
1844
  runtime = ensure_runtime_ready()
 
2166
  async def analyze_endpoint(
2167
  request: Request,
2168
  playerId: str = Form(...),
 
 
2169
  clientId: str = Form(...),
2170
  videoOrders: List[int] = Form(...),
2171
  actionsJson: UploadFile = File(...),
 
2198
 
2199
  calib_path = os.path.join(session_dir, "calibration.npz")
2200
  await save_upload_to_path(calibration, calib_path)
2201
+ target_size = read_calibration_target_size(calib_path)
2202
 
2203
  camera_map = {}
2204
  for idx, (camera_order, video) in enumerate(zip(videoOrders, videos)):
 
2224
  run_analysis_job,
2225
  request_base_url,
2226
  playerId,
2227
+ target_size,
 
2228
  clientId,
2229
  session_id,
2230
  session_dir,
 
2271
  async def analyze_endpoint_inline(
2272
  request: Request,
2273
  playerId: str = Form(...),
 
 
2274
  clientId: str = Form(...),
2275
  videoOrders: List[int] = Form(...),
2276
  actionsJson: UploadFile = File(...),
 
2296
  calib_path = os.path.join(session_dir, "calibration.npz")
2297
  with open(calib_path, "wb") as f:
2298
  f.write(await calibration.read())
2299
+ target_w, target_h = read_calibration_target_size(calib_path)
2300
 
2301
  if len(videoOrders) != len(videos):
2302
  raise ValueError("Each uploaded video must include a matching camera order")
 
2326
  }
2327
 
2328
  sizes = {
2329
+ "TARGET_SIZE": (int(target_w), int(target_h)),
2330
  "YOLO_IMGSZ": 960
2331
  }
2332
 
 
2554
  "id": session_id,
2555
  "playerId": playerId,
2556
  "createdAt": int(time.time() * 1000),
2557
+ "targetSize": [int(target_w), int(target_h)],
2558
  "cameraCount": len(camera_map),
2559
  "actions": formatted_actions,
2560
  "failedActions": failed_actions