How jnr-10/visor-video-instance-segmentation-and-object-retrieval works
1. Repo shape
- VISOR is a two-tier application: a FastAPI backend that handles video ingestion and ML processing, and a Next.js 14 frontend that presents the video, overlays detections, and product matches.
- The system is designed to work in a mostly stateless local-file mode, with an optional database layer present but not the primary runtime dependency.
2. User-facing flow
- The main path is: upload video → backend stores it → processing pipeline runs → frontend polls status and renders interactive results.
- The frontend is not doing ML itself; it is a thin presentation layer that consumes backend APIs and draws overlays on top of video playback.
3. Backend API boundary
- The backend is organized around small route modules in backend/app/api/: videos, process, events, and health.
- These separate concerns cleanly:
- videos for upload/storage
- process for starting and monitoring analysis
- events for analytics/logging
- health for readiness checks
4. Processing pipeline boundary
- The core domain logic lives in backend/app/services/.
- video_processor.py appears to orchestrate the end-to-end pipeline, while:
- frame_extractor.py handles frame sampling
- grounding_dino_service.py performs zero-shot object detection
- segmentation_service.py performs pixel-level masking
- product_search.py maps detected objects to shopping results
- This is the main architectural boundary: the API layer triggers processing, but services own the ML/video workflow.
5. ML/model subsystem
- The repo is centered on a detection stack using OWL-ViT / Grounding-style zero-shot detection, SAM 2 segmentation, and optional CLIP-based product embeddings.
- These are not embedded in the frontend; they are backend-only model integrations, likely loaded from data/models/ and chosen based on the configured device (cuda, mps, or cpu).
6. State and storage
- Runtime artifacts are stored on the local filesystem under data/, with the README indicating folders for videos, frames, crops, masks, and tracking outputs.
- This makes the backend portable and supports the stated “stateless mode,” where processing can happen without a mandatory database.
- backend/app/core/cache.py likely provides transient progress/status tracking, which fits the real-time processing UX.
7. Database boundary
- There is a database layer in backend/app/core/database.py plus ORM-style models in backend/app/models/db_models.py, and SQL scripts in scripts/init_db.sql and scripts/add_category_column.sql.
- However, the README explicitly says the database is optional / currently disabled for portability, so in the current architecture it should be treated as a secondary capability rather than a required subsystem.
8. Frontend boundary
- The frontend is a Next.js App Router application in frontend/src/app/.
- Key UI components are:
- VideoPlayer.tsx for playback and overlay interaction
- ProductDrawer.tsx for showing matched shopping results
- frontend/src/lib/api.ts is the API boundary between the UI and the backend, and types/ defines the shared response shapes expected from the backend.
9. Interaction model
- The frontend likely polls the backend for processing progress and retrieved tracking data, rather than receiving a live stream.
- The backend exposes a progress/status endpoint and logs, so the UX is driven by incremental status updates and then interactive object selection once processing completes.
10. External service integration
- The only clearly material external service is SerpAPI, used by product_search.py to return real shopping results.
- This means product matching is a hybrid of local detection and external search, with the search call sitting behind the backend so the frontend never talks directly to SerpAPI.
11. Observability and health
- The events endpoint provides application-level analytics, such as object clicks, which can be used for usage tracking or product interaction metrics.
- health supports operational checks for deployment and startup verification.
12. Operational/tooling layer
- The repo includes setup and validation scripts (verify_env.py, test_processing.py, SQL init scripts), which suggests the project is meant to be run both locally and in reproducible dev environments.
- The stack materially depends on Python 3.10+, FastAPI, Next.js 14, OpenCV/FFmpeg, and optional GPU acceleration for acceptable processing speed.
13. How to draw the architecture
- A clear diagram should show:
- Browser/UI
- Next.js frontend
- FastAPI backend
- Local storage under data/
- ML processing pipeline/services
- Optional PostgreSQL
- External SerpAPI
- The main arrows are:
- upload from frontend to backend
- processing from API into services/models
- artifact writes to filesystem
- status/result reads back to frontend
- product queries out to SerpAPI
Main entry points: video_processor.py Video Processor · main.py FastAPI App · api.ts API Client · app Next.js App
Components 21
Browser & UI
User-facing playback and results presentation
- Browser · User interface for uploading videos, viewing overlays, and exploring matches
Frontend
Next.js application and client API layer
- Next.js App · App Router frontend that renders the experience and polls backend results
frontend/src/app - Video Player · Plays video and renders interactive overlays
frontend/src/components/VideoPlayer.tsx - Product Drawer · Shows matched shopping results and details
frontend/src/components/ProductDrawer.tsx - API Client · Frontend-to-backend request layer and response handling
frontend/src/lib/api.ts
Backend API
FastAPI route boundary
- FastAPI App · Backend application entrypoint and route assembly
backend/app/main.py - Videos API · Video upload and storage endpoints
backend/app/api/videos.py - Process API · Start and monitor analysis processing
backend/app/api/process.py - Events API · Analytics and interaction logging endpoints
backend/app/api/events.py - Health API · Readiness and operational checks
backend/app/api/health.py
Backend Core
Runtime state and configuration
- Config · Environment and runtime configuration
backend/app/core/config.py - Progress Cache · Transient progress and status tracking
backend/app/core/cache.py
Processing Pipeline
Video, detection, segmentation, and product matching
- Video Processor · Coordinates the end-to-end analysis workflow
backend/app/services/video_processor.py - Frame Extractor · Samples frames from uploaded video
backend/app/services/frame_extractor.py - Grounding DINO · Zero-shot object detection integration
backend/app/services/grounding_dino_service.py - Segmentation · Pixel-level masking and instance refinement
backend/app/services/segmentation_service.py - Product Search · Maps detections to shopping results via external search
backend/app/services/product_search.py
Storage
Local artifacts and optional database
- Data Files · Videos, frames, crops, masks, and tracking artifacts
data - Database Layer · Optional persistence layer for enabled deployments
backend/app/core/database.py - SerpAPI · External shopping search provider used for product matching
Operations
Setup, validation, and maintenance scripts
- Ops Scripts · Environment verification, processing tests, and SQL setup
scripts
Connections 26
- Browser → Next.js App: use · Users interact with the web app
- Next.js App → API Client: calls · UI requests backend data and actions
- API Client → Videos API: upload · Uploads video files
- API Client → Process API: start/status · Starts processing and polls progress
- API Client → Events API: log · Sends interaction analytics
- API Client → Health API: check · Checks backend readiness
- Next.js App → Video Player: renders · Displays playback and overlays
- Next.js App → Product Drawer: renders · Displays product matches
- FastAPI App → Videos API: mounts · Registers video routes
- FastAPI App → Process API: mounts · Registers process routes
- FastAPI App → Events API: mounts · Registers event routes
- FastAPI App → Health API: mounts · Registers health routes
- Videos API → Data Files: writes · Stores uploaded media locally
- Process API → Progress Cache: updates · Exposes progress and status
- Process API → Video Processor: triggers · Starts the analysis pipeline
- Video Processor → Frame Extractor: uses · Extracts frames for analysis
- Video Processor → Grounding DINO: uses · Detects objects with zero-shot models
- Video Processor → Segmentation: uses · Builds masks for detected instances
- Video Processor → Product Search: uses · Finds candidate products
- Video Processor → Data Files: writes · Persists frames, masks, and tracking outputs
- Product Search → SerpAPI: queries · Fetches external shopping results
- Video Processor → Database Layer: optional write · Persists metadata when database is enabled
- Events API → Database Layer: optional write · Stores analytics when persistence is enabled
- Health API → Config: reads · Uses runtime configuration for readiness checks
- FastAPI App → Config: reads · Loads application settings
- Ops Scripts → Database Layer: initializes · Prepares optional database schema