Silent Voice
Silent Voice
def load_model():
model_path = "C:/Users/ARYAN/Desktop/model.p"
with open(model_path, 'rb') as f:
model_data = pickle.load(f)
return model_data['model']
def start_detection():
global cap, running
running = True
cap = cv2.VideoCapture(0)
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(static_image_mode=False, min_detection_confidence=0.6)
labels_dict = {0: 'Hi', 1: 'Yes', 2: 'No', 3: 'Thank You', 4: 'I Love You'}
model = load_model()
def detect():
global running
while running:
ret, frame = cap.read()
if not ret:
continue
frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = hands.process(frame_rgb)
if results.multi_hand_landmarks:
for hand_landmarks in results.multi_hand_landmarks:
data_aux = []
x_ = [lm.x for lm in hand_landmarks.landmark]
y_ = [lm.y for lm in hand_landmarks.landmark]
for lm in hand_landmarks.landmark:
data_aux.append(lm.x - min(x_))
data_aux.append(lm.y - min(y_))
if len(data_aux) == model.n_features_in_:
confidence =
max(model.predict_proba([np.asarray(data_aux)])[0])
if confidence < 0.6:
detected_label.set("No sign detected")
continue
prediction = model.predict([np.asarray(data_aux)])[0]
detected_label.set(labels_dict[int(prediction)])
video_label.imgtk = imgtk
video_label.config(image=imgtk)
cap.release()
cv2.destroyAllWindows()
Thread(target=detect, daemon=True).start()
def stop_detection():
global running
running = False
# GUI Setup
root = tk.Tk()
root.title("ASL Detection")
root.geometry("700x600")
detected_label = tk.StringVar()
detected_label.set("Waiting...")
video_label = ttk.Label(frame)
video_label.pack(pady=10)
root.mainloop()