GeraldoRiberia commited on
Commit
1949831
·
1 Parent(s): 514a298

zoom scaling + backend fixes

Browse files
Files changed (2) hide show
  1. .env +1 -1
  2. server.py +15 -14
.env CHANGED
@@ -5,7 +5,7 @@ JWT_SECRET_KEY=your-secret-key-change-in-production
5
 
6
  # MongoDB Configuration
7
  # Connection string for MongoDB database
8
- MONGODB_URI=mongodb+srv://arnavjagadeesh09_db_user:aP4x5QkUdSThzpxT@cluster0.uo44a8g.mongodb.net/?appName=Cluster0
9
 
10
  # MongoDB database name
11
  MONGODB_DB=afs
 
5
 
6
  # MongoDB Configuration
7
  # Connection string for MongoDB database
8
+ MONGODB_URI=mongodb+srv://mainuser:DPzm5VGHWiJ84ECp@afs-cluster.qdjmsq8.mongodb.net/?appName=AFS-Cluster
9
 
10
  # MongoDB database name
11
  MONGODB_DB=afs
server.py CHANGED
@@ -51,6 +51,7 @@ recording_filename = ""
51
  current_cx = 0.5
52
  current_cy = 0.5
53
  current_scale = 1.0
 
54
 
55
  # --- Real-time Target Tracking State ---
56
  current_target_angle = None
@@ -213,7 +214,7 @@ def apply_center_stage_crop(frame, tracking_data):
213
  the frame based on the tracking target bounding box.
214
  Returns the cropped frame.
215
  """
216
- global current_cx, current_cy, current_scale, current_target_angle, current_target_distance
217
 
218
  h, w = frame.shape[:2]
219
 
@@ -266,6 +267,9 @@ def apply_center_stage_crop(frame, tracking_data):
266
  target_scale = max(1.0, min(target_scale, 3.0))
267
 
268
  if target_found:
 
 
 
269
  # Calculate distance and angle from the frame center (w/2, h/2) to the target bounding box center (box_cx, box_cy)
270
  center_x, center_y = w / 2.0, h / 2.0
271
 
@@ -420,8 +424,7 @@ async def startup_event():
420
  await users_collection.create_index("email", unique=True)
421
  logger.info("Connected to MongoDB and initialized collections.")
422
  except Exception as e:
423
- logger.warning(f"MongoDB connection failed on startup: {
424
- e}. Starting reconnection loop.")
425
  mongo_client = None
426
  users_collection = None
427
  audio_recordings_collection = None
@@ -512,7 +515,7 @@ async def verify_token(current_user: UserPublic = Depends(get_current_user)):
512
 
513
  @app.websocket("/ws")
514
  async def websocket_endpoint(websocket: WebSocket):
515
- global is_recording, video_writer, recording_filename, latest_obs_frame, is_obs_active
516
 
517
  await websocket.accept()
518
  logger.info("New WebSocket connection established.")
@@ -528,20 +531,20 @@ async def websocket_endpoint(websocket: WebSocket):
528
  try:
529
  payload = json.loads(message["text"])
530
  if "mode" in payload and payload["mode"] != current_mode:
531
- logger.info(f"Switching mode from {
532
- current_mode} to {payload['mode']}")
533
  current_mode = payload["mode"]
534
  await websocket.send_json({"type": "mode_ack", "mode": current_mode})
 
 
 
535
  elif "command" in payload:
536
  # Handle recording commands
537
  command = payload["command"]
538
  if command == "start_recording":
539
  if not is_recording:
540
  is_recording = True
541
- recording_filename = f"capture_{
542
- datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
543
- logger.info(f"Started recording to {
544
- recording_filename}")
545
  await websocket.send_json({"type": "recording_ack", "status": "started"})
546
  elif command == "stop_recording":
547
  if is_recording:
@@ -549,8 +552,7 @@ async def websocket_endpoint(websocket: WebSocket):
549
  if video_writer is not None:
550
  video_writer.release()
551
  video_writer = None
552
- logger.info(f'''Stopped recording. File saved as {
553
- recording_filename}''')
554
  elif command == "start_obs":
555
  if not is_obs_active:
556
  is_obs_active = True
@@ -589,8 +591,7 @@ async def websocket_endpoint(websocket: WebSocket):
589
  executor, run_inference, frame, current_mode
590
  )
591
  except Exception as e:
592
- logger.error(f"Error processing frame in {
593
- current_mode} mode: {e}")
594
  response_data = {"error": str(e)}
595
 
596
  # Send results back to client
 
51
  current_cx = 0.5
52
  current_cy = 0.5
53
  current_scale = 1.0
54
+ zoom_multiplier = 1.0
55
 
56
  # --- Real-time Target Tracking State ---
57
  current_target_angle = None
 
214
  the frame based on the tracking target bounding box.
215
  Returns the cropped frame.
216
  """
217
+ global current_cx, current_cy, current_scale, current_target_angle, current_target_distance, zoom_multiplier
218
 
219
  h, w = frame.shape[:2]
220
 
 
267
  target_scale = max(1.0, min(target_scale, 3.0))
268
 
269
  if target_found:
270
+ # Apply user zoom multiplier
271
+ target_scale = max(1.0, min(target_scale * zoom_multiplier, 10.0))
272
+
273
  # Calculate distance and angle from the frame center (w/2, h/2) to the target bounding box center (box_cx, box_cy)
274
  center_x, center_y = w / 2.0, h / 2.0
275
 
 
424
  await users_collection.create_index("email", unique=True)
425
  logger.info("Connected to MongoDB and initialized collections.")
426
  except Exception as e:
427
+ logger.warning(f"MongoDB connection failed on startup: {e}. Starting reconnection loop.")
 
428
  mongo_client = None
429
  users_collection = None
430
  audio_recordings_collection = None
 
515
 
516
  @app.websocket("/ws")
517
  async def websocket_endpoint(websocket: WebSocket):
518
+ global is_recording, video_writer, recording_filename, latest_obs_frame, is_obs_active, zoom_multiplier
519
 
520
  await websocket.accept()
521
  logger.info("New WebSocket connection established.")
 
531
  try:
532
  payload = json.loads(message["text"])
533
  if "mode" in payload and payload["mode"] != current_mode:
534
+ logger.info(f"Switching mode from {current_mode} to {payload['mode']}")
 
535
  current_mode = payload["mode"]
536
  await websocket.send_json({"type": "mode_ack", "mode": current_mode})
537
+ elif "zoom_scale" in payload:
538
+ zoom_multiplier = float(payload["zoom_scale"])
539
+ logger.info(f"Updated zoom multiplier to {zoom_multiplier}")
540
  elif "command" in payload:
541
  # Handle recording commands
542
  command = payload["command"]
543
  if command == "start_recording":
544
  if not is_recording:
545
  is_recording = True
546
+ recording_filename = f"capture_{datetime.now().strftime('%Y%m%d_%H%M%S')}.mp4"
547
+ logger.info(f"Started recording to {recording_filename}")
 
 
548
  await websocket.send_json({"type": "recording_ack", "status": "started"})
549
  elif command == "stop_recording":
550
  if is_recording:
 
552
  if video_writer is not None:
553
  video_writer.release()
554
  video_writer = None
555
+ logger.info(f'''Stopped recording. File saved as {recording_filename}''')
 
556
  elif command == "start_obs":
557
  if not is_obs_active:
558
  is_obs_active = True
 
591
  executor, run_inference, frame, current_mode
592
  )
593
  except Exception as e:
594
+ logger.error(f"Error processing frame in {current_mode} mode: {e}")
 
595
  response_data = {"error": str(e)}
596
 
597
  # Send results back to client