ibrahim313 commited on
Commit
1edd41b
·
verified ·
1 Parent(s): 9c5f577

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -9,17 +9,19 @@ mp_hands = mp.solutions.hands
9
  hands = mp_hands.Hands(static_image_mode=False, max_num_hands=1, min_detection_confidence=0.5)
10
  mp_drawing = mp.solutions.drawing_utils
11
 
12
- # Function to recognize gestures
13
- def get_gesture(landmarks):
14
  thumb_tip = landmarks[4]
15
  index_tip = landmarks[8]
16
-
17
- if thumb_tip.y < index_tip.y:
18
- return 'Thumbs Up'
19
- elif thumb_tip.y > landmarks[0].y:
20
- return 'Thumbs Down'
21
- else:
22
- return 'Other Gesture'
 
 
23
 
24
  # Process hand gestures
25
  def process_hand(image):
@@ -29,18 +31,19 @@ def process_hand(image):
29
  if results.multi_hand_landmarks:
30
  for hand_landmarks in results.multi_hand_landmarks:
31
  mp_drawing.draw_landmarks(image, hand_landmarks, mp_hands.HAND_CONNECTIONS)
32
-
33
  landmarks = hand_landmarks.landmark
34
- gesture = get_gesture(landmarks)
35
 
36
- # Draw the recognized gesture on the image
37
- cv2.putText(image, gesture, (10, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
38
-
 
 
 
39
  return image
40
 
41
  # Streamlit Interface
42
  st.title("AI Sign Language Interpreter")
43
- st.write("Make a thumbs up or thumbs down gesture in front of your camera, or upload an image.")
44
 
45
  # Use Streamlit's built-in camera input
46
  video_input = st.camera_input("Take a picture with your webcam")
 
9
  hands = mp_hands.Hands(static_image_mode=False, max_num_hands=1, min_detection_confidence=0.5)
10
  mp_drawing = mp.solutions.drawing_utils
11
 
12
+ # Function to recognize letters based on hand landmarks
13
+ def get_letter(landmarks):
14
  thumb_tip = landmarks[4]
15
  index_tip = landmarks[8]
16
+
17
+ # Example conditions for gesture recognition (you can expand this logic)
18
+ if thumb_tip.y < index_tip.y: # Example condition for 'A'
19
+ return 'A'
20
+ elif thumb_tip.y > landmarks[0].y: # Example condition for 'B'
21
+ return 'B'
22
+ # Add more conditions for other letters
23
+ # Return 'Unknown' if no match
24
+ return 'Unknown'
25
 
26
  # Process hand gestures
27
  def process_hand(image):
 
31
  if results.multi_hand_landmarks:
32
  for hand_landmarks in results.multi_hand_landmarks:
33
  mp_drawing.draw_landmarks(image, hand_landmarks, mp_hands.HAND_CONNECTIONS)
 
34
  landmarks = hand_landmarks.landmark
 
35
 
36
+ # Get recognized letter
37
+ letter = get_letter(landmarks)
38
+
39
+ # Draw the recognized letter on the image
40
+ cv2.putText(image, letter, (10, 50), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
41
+
42
  return image
43
 
44
  # Streamlit Interface
45
  st.title("AI Sign Language Interpreter")
46
+ st.write("Make a gesture in front of your camera, or upload an image.")
47
 
48
  # Use Streamlit's built-in camera input
49
  video_input = st.camera_input("Take a picture with your webcam")