-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinference_classifier.py
More file actions
44 lines (33 loc) · 1.3 KB
/
Copy pathinference_classifier.py
File metadata and controls
44 lines (33 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import cv2
import numpy as np
import streamlit as st
from PIL import Image
import os
# ✅ Updated Mediapipe import
from mediapipe import solutions as mp_solutions
from isl_utils import load_model, extract_landmarks, predict
MODEL_FILE = "./model.p"
st.title("✋ ISL Gesture → Alphabet Recognition")
if not os.path.exists(MODEL_FILE):
st.error("❌ No trained model found. Please run train_classifier.py first.")
st.stop()
model = load_model(MODEL_FILE)
st.write("📷 Show a hand gesture to the camera below:")
img_file = st.camera_input("Capture gesture")
if img_file is not None:
image = Image.open(img_file)
frame = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
rgb_img = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
# ✅ Updated mediapipe usage
with mp_solutions.hands.Hands(
static_image_mode=True,
min_detection_confidence=0.3
) as hands_detector:
results = hands_detector.process(rgb_img)
if results.multi_hand_landmarks:
hand_landmarks = results.multi_hand_landmarks[0]
landmarks = extract_landmarks(hand_landmarks)
predicted_letter = predict(model, landmarks)
st.success(f"✅ Predicted gesture: **{predicted_letter}**")
else:
st.warning("⚠️ No hand detected. Try again.")