Skip to content

Fix: add confidence threshold and prevent UI freezing on empty states#7

Open
khushanuma-shabbir wants to merge 1 commit into
Sant60:mainfrom
khushanuma-shabbir:fix/confidence-threshold-ui-freeze
Open

Fix: add confidence threshold and prevent UI freezing on empty states#7
khushanuma-shabbir wants to merge 1 commit into
Sant60:mainfrom
khushanuma-shabbir:fix/confidence-threshold-ui-freeze

Conversation

@khushanuma-shabbir
Copy link
Copy Markdown

Summary

This PR improves real-time prediction stability and fixes a bug where the
UI freezes when a hand leaves the camera frame.

Problem

Two issues existed in the prediction pipeline:

  1. No confidence threshold — The model accepted the top prediction even
    at very low confidence (e.g., 15%). During hand transitions or random
    movements, the UI rapidly flickered with incorrect letters, and the
    5-second auto-add timer could trigger erroneously.

  2. UI freezing on empty state — When a hand left the frame,
    detector.findHands() returned empty and the backend responded with
    {"success": False}. The frontend ignored this response, leaving the
    last detected letter permanently frozen on screen.

Changes Made

app.py

  • Added CONFIDENCE_THRESHOLD = 0.70 constant (70% minimum confidence)
  • Predictions below threshold now return "Unsure" and reset the
    auto-add timer, preventing false letter triggers
  • When no hand is detected, now returns success: True with "Waiting..."
    so the frontend clears the screen properly
  • Fixed edge case: if hand crop is empty (imgCrop.size == 0), state
    variables are now reset before returning

templates/index.html

  • Updated JS to display "Waiting..." and "Unsure" cleanly without
    appending (0%) to the string

Testing Steps

  1. Run python app.py and open http://127.0.0.1:5000
  2. Hold a clear ASL sign — verify it shows the letter with confidence %
  3. Slowly blur or rotate your hand — verify it shows "Unsure" instead
    of a random letter
  4. Remove your hand from the frame entirely — verify screen clears to
    "Waiting..." immediately instead of freezing
  5. Hold a valid sign for 5 seconds — verify the auto-add still works
    correctly for high-confidence predictions

Why This Improves the Project

  • Eliminates false positives during hand transitions
  • Makes the auto-add delay more reliable (only counts stable, high-confidence signs)
  • Ensures users always know the app state (Waiting / Unsure / Confident)
  • Prevents confusion from a frozen UI after moving hand out of frame

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.

1 participant