Skip to content

Add backend + link with CV model#5

Open
trandaiviethung2001 wants to merge 4 commits into
mainfrom
v2-update
Open

Add backend + link with CV model#5
trandaiviethung2001 wants to merge 4 commits into
mainfrom
v2-update

Conversation

@trandaiviethung2001
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a comprehensive web-based dashboard for real-time missing person detection, featuring a FastAPI backend and a Leaflet-powered frontend. The core detection logic has been refactored into a reusable pipeline class, and new services for database management and embedding training have been added. Feedback focuses on restoring CLI functionality in the standalone script, implementing atomic file swaps for the embeddings database, and fixing a potential division-by-zero error in the streaming service. Recommendations were also made to decouple recording frame rates from UI streaming rates and to adopt modern FastAPI lifespan management.

Comment thread detect_missing_person.py Outdated
Comment on lines 547 to 555
video_source = 0

main(
video_path=video_source,
output_path=args.output,
threshold=args.threshold,
frame_skip=args.skip,
no_display=args.no_display
output_path=None,
threshold=None,
frame_skip=None,
no_display=False,
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The removal of the argparse logic and hardcoding video_source = 0 is a significant regression. This script can no longer be used to process video files or specify different camera IDs via the command line, which breaks the documented usage and reduces the utility of the standalone script.

db_dir=str(self.settings.missing_persons_db_dir),
output_path=str(versioned_output),
)
shutil.copy2(versioned_output, root_output)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

Using shutil.copy2 to overwrite the active database file is not atomic. If the process is interrupted or if the detector service attempts to read the file during the copy, it could result in a corrupted file or an EOFError during unpickling. It is recommended to copy to a temporary file first and then use os.replace() (or Path.replace()) for an atomic swap.

else:
self._send_detection_if_changed(self._empty_detection())

if now - last_stream_sent >= max(0.01, 1.0 / self.settings.stream_fps):
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This line will raise a ZeroDivisionError if stream_fps is configured as 0. It is safer to validate this setting or add a check before division.

Suggested change
if now - last_stream_sent >= max(0.01, 1.0 / self.settings.stream_fps):
if self.settings.stream_fps > 0 and now - last_stream_sent >= max(0.01, 1.0 / self.settings.stream_fps):

timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
path = self.settings.recording_dir / f"recording_{timestamp}.mp4"
fourcc = cv2.VideoWriter_fourcc(*"mp4v")
return cv2.VideoWriter(str(path), fourcc, max(1.0, self.settings.stream_fps), (width, height))
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The recording FPS is hardcoded to stream_fps, which is the UI streaming rate. If the actual processing rate (inference speed) is different from this value, the saved video will play back at an incorrect speed (too fast or too slow). It is recommended to use the actual source FPS or the measured processing FPS for the VideoWriter.

Comment on lines +65 to +73
@app.on_event("startup")
async def on_startup() -> None:
manager.attach_loop(asyncio.get_running_loop())
runtime.ensure_started()


@app.on_event("shutdown")
async def on_shutdown() -> None:
runtime.shutdown()
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The @app.on_event decorators for startup and shutdown are deprecated in FastAPI. It is recommended to use the lifespan context manager instead for managing the application lifecycle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants