product-recognition-demo/recognization
kiyo9w 5f84f4f2a7 feat: recognition server API, reference stream client, and live label memory
app.py becomes the recognition server: /v1 REST (health, catalog + template
images, samples, recognize, classify, inspect, stock) plus /v1/stream over
WebSocket, with token auth, size limits, one consistent error shape, and the
legacy /api/sessions routes kept but now backed by the real engine instead of
the fake adapter. Default bind is 127.0.0.1; LAN and TLS are opt-in.

stream_client.py is the reference non-browser client (camera, video file, or a
pan across a still) and prints results/s, RTT, detect time and label stability.

Live quality work driven by measurements:
- Labels are remembered per place: a fresh track covering a recently recognized
  product inherits the label instead of queueing for classification again. On a
  continuous pan this raised recognized products in view from 9/66 to 17-21/66
  and cut time-to-first-label to ~1.6 s.
- Classification priority is newest-first, because sorting by area spends the
  budget on products that are already leaving the frame.
- Per-session classification concurrency raised to 12.

hybrid_fast (ORB shortlist then hybrid) is implemented but NOT the default: it
is 3.4x faster (13 ms vs 44 ms p50) yet agreed with hybrid on only 47% of
accepted crops across 553 crops, far below the 98% adoption rule. It stays
available for experiments; the numbers are in the commit and the benchmark.

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-09-24 12:31:17 +09:00
..
add Initial commit for push folder 2026-09-18 09:13:53 +09:00
code feat: recognition server API, reference stream client, and live label memory 2026-09-24 12:31:17 +09:00
runs/detect/train Initial commit for push folder 2026-09-18 09:13:53 +09:00
stock update stock file 2026-09-18 09:59:06 +09:00
.gitignore Initial commit for push folder 2026-09-18 09:13:53 +09:00
detected_empty_slots.jpg Initial commit for push folder 2026-09-18 09:13:53 +09:00
detected_image.jpg Initial commit for push folder 2026-09-18 09:13:53 +09:00
image.jpg Initial commit for push folder 2026-09-18 09:13:53 +09:00
README.md Initial commit for push folder 2026-09-18 09:13:53 +09:00
requirements-dev.txt refactor: make the matcher and detector safe for concurrent clients 2026-09-24 11:43:24 +09:00
requirements.txt refactor: make the matcher and detector safe for concurrent clients 2026-09-24 11:43:24 +09:00
run_app.bat Initial commit for push folder 2026-09-18 09:13:53 +09:00
run_app.sh Initial commit for push folder 2026-09-18 09:13:53 +09:00
supermarket_diagram.png Initial commit for push folder 2026-09-18 09:13:53 +09:00
test_empty_slots.jpg Initial commit for push folder 2026-09-18 09:13:53 +09:00

🍡 Dorayaki - Smart Supermarket Shelf AI & Inventory Recognition

Hệ thống nhận diện sản phẩm trên kệ siêu thị và quản lý tồn kho thời gian thực dựa trên kiến trúc kết hợp YOLO (Object Detection) và Local Feature Matching (SURF / SIFT, ORB, BRISK, Hybrid) theo paper quốc tế (Electronics 2023, 12, 3640).


📋 Yêu cầu hệ thống (System Requirements)

  • Hệ điều hành: Windows 10/11, macOS hoặc Linux (Ubuntu/Debian).
  • Python: Python 3.9, 3.10 hoặc 3.11 (khuyên dùng Python 3.10).
  • Phần cứng: CPU tối thiểu 4 lõi, RAM 8GB (có GPU NVIDIA là lợi thế nhưng CPU chạy hoàn toàn mượt mà).

🚀 Hướng dẫn cài đặt và chạy Step-by-Step

Bước 1: Sao chép toàn bộ thư mục dự án sang máy mới

Đảm bảo bạn copy toàn bộ thư mục dự án, đặc biệt là các thư mục cốt lõi:

  • code/: Toàn bộ mã nguồn backend, frontend, thuật toán nhận diện.

uns/: Chứa file trọng số mô hình YOLO đã train ( uns/detect/train/weights/best.pt).

  • stock/: Chứa file catalog stock.csv và ảnh mẫu sản phẩm chuẩn sku_001 -> sku_016.
  • dd/ & image.jpg: Các ảnh kệ hàng mẫu để test và demo.

equirements.txt: Danh sách thư viện cần thiết.

Bước 2: Tạo môi trường ảo Python (Khuyên dùng)

Mở Terminal / PowerShell / Command Prompt tại thư mục dự án:

Cách 1: Sử dụng Conda (Khuyên dùng nếu đã cài Anaconda/Miniconda)

ash conda create -n dorayaki python=3.10 -y conda activate dorayaki

Cách 2: Sử dụng venv chuẩn của Python

  • Trên Windows: ash python -m venv venv venv\Scripts\activate
  • Trên macOS / Linux: ash python3 -m venv venv source venv/bin/activate

Bước 3: Cài đặt các thư viện phụ thuộc

Chạy lệnh sau để cài đặt toàn bộ package: ash pip install -r requirements.txt

(Ghi chú nếu máy có GPU NVIDIA và muốn tăng tốc độ YOLO, có thể cài PyTorch CUDA theo hướng dẫn tại pytorch.org).

Bước 4: Khởi chạy ứng dụng Dorayaki Web App

Cách 1: Chạy bằng lệnh Python

ash python code/app.py --port 8080 (Nếu dùng macOS/Linux có thể dùng python3 code/app.py --port 8080)

Cách 2: Chạy nhanh bằng script có sẵn

  • Trên Windows: Click đúp vào file un_app.bat
  • Trên Linux/macOS: Chạy ./run_app.sh

Bước 5: Mở ứng dụng trên trình duyệt

Mở trình duyệt (Chrome, Edge, Safari, Firefox) và truy cập: 👉 http://localhost:8080 (hoặc http://127.0.0.1:8080)


🛠️ Các lệnh kiểm tra hệ thống (Test Scripts)

  1. Test toàn diện hệ thống (Test Suite): ash python code/test_suite.py
  2. Test nhận diện sản phẩm trên ảnh image.jpg: ash python code/test_image.py
  3. Test nhận diện các chỗ trống trên kệ (Empty Shelf Slots): ash python code/test_empty.py (Kết quả trực quan sẽ được xuất ra file detected_empty_slots.jpg với viền đỏ bao quanh các vị trí hết hàng).

🌟 Các tính năng chính của ứng dụng

  1. Phát hiện sản phẩm (YOLO): Tự động detect hơn 170+ vật phẩm trên kệ trong 1 lượt scan.
  2. Phát hiện chỗ trống trên kệ (Out-of-Stock Detection): Tự động phát hiện các vị trí hết hàng và khoanh đỏ, ước lượng số lượng sản phẩm đang thiếu.
  3. Phân loại đa thuật toán: Cho phép chọn giữa Hybrid (Paper), SURF / SIFT, ORB, BRISK.
  4. Tương tác trực quan: Click vào bất kỳ sản phẩm nào trên ảnh kệ để xem tên, giá, ngày nhập, hạn sử dụng, số lượng tồn kho và xem các điểm matching inliers.
  5. Đa ngôn ngữ: Hỗ trợ chuyển đổi nhanh Tiếng Anh và Tiếng Nhật.
  6. Tải ảnh linh hoạt: Chọn ảnh từ danh mục mẫu, chụp ảnh trực tiếp từ webcam/camera điện thoại, hoặc upload ảnh từ máy tính.