├── README.md ├── Untitled-1.py ├── collect_image.py ├── create_dataset.py ├── data.pickle ├── demo.py ├── inferance_classifier.py ├── model.p └── train_classifer.py /README.md: -------------------------------------------------------------------------------- 1 | Overview 2 | This project aims to develop a system capable of recognizing sign language gestures and translating them into text or spoken language. Sign language is a crucial means of communication for people with hearing impairments, and this project seeks to bridge the communication gap by leveraging machine learning and computer vision techniques. 3 | 4 | Features 5 | *Real-time sign language gesture recognition. 6 | *Translation of recognized gestures into text or spoken language. 7 | *Support for multiple sign languages (e.g., American Sign Language, British Sign Language, etc.). 8 | *User-friendly interface for easy interaction. 9 | Technologies Used 10 | *Python 11 | *OpenCV for computer vision tasks 12 | *TensorFlow or PyTorch for deep learning models 13 | *Flask for creating a web interface (optional) 14 | *HTML/CSS/JavaScript (if developing a web interface) 15 | Setup 16 | Clone this repository to your local machine. 17 | bash 18 | Copy code 19 | git clone https://github.com/your_username/sign-language-recognition.git 20 | Install the required dependencies. 21 | bash 22 | Copy code 23 | pip install -r requirements.txt 24 | -------------------------------------------------------------------------------- /Untitled-1.py: -------------------------------------------------------------------------------- 1 | # OpenCV program to detect face in real time 2 | # import libraries of python OpenCV 3 | # where its functionality resides 4 | import cv2 5 | 6 | # load the required trained XML classifiers 7 | # https://github.com/Itseez/opencv/blob/master/ 8 | # data/haarcascades/haarcascade_frontalface_default.xml 9 | # Trained XML classifiers describes some features of some 10 | # object we want to detect a cascade function is trained 11 | # from a lot of positive(faces) and negative(non-faces) 12 | # images. 13 | face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default.xml') 14 | 15 | # https://github.com/Itseez/opencv/blob/master 16 | # /data/haarcascades/haarcascade_eye.xml 17 | # Trained XML file for detecting eyes 18 | eye_cascade = cv2.CascadeClassifier('haarcascade_eye.xml') 19 | 20 | # capture frames from a camera 21 | cap = cv2.VideoCapture(0) 22 | 23 | # loop runs if capturing has been initialized. 24 | while 1: 25 | 26 | # reads frames from a camera 27 | ret, img = cap.read() 28 | 29 | # convert to gray scale of each frames 30 | gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 31 | 32 | # Detects faces of different sizes in the input image 33 | faces = face_cascade.detectMultiScale(gray, 1.3, 5) 34 | 35 | for (x,y,w,h) in faces: 36 | # To draw a rectangle in a face 37 | cv2.rectangle(img,(x,y),(x+w,y+h),(255,255,0),2) 38 | roi_gray = gray[y:y+h, x:x+w] 39 | roi_color = img[y:y+h, x:x+w] 40 | 41 | # Detects eyes of different sizes in the input image 42 | eyes = eye_cascade.detectMultiScale(roi_gray) 43 | 44 | #To draw a rectangle in eyes 45 | for (ex,ey,ew,eh) in eyes: 46 | cv2.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,127,255),2) 47 | 48 | # Display an image in a window 49 | cv2.imshow('img',img) 50 | 51 | # Wait for Esc key to stop 52 | k = cv2.waitKey(30) & 0xff 53 | if k == 27: 54 | break 55 | 56 | # Close the window 57 | cap.release() 58 | 59 | # De-allocate any associated memory usage 60 | cv2.destroyAllWindows() 61 | -------------------------------------------------------------------------------- /collect_image.py: -------------------------------------------------------------------------------- 1 | import os 2 | import cv2 3 | from time import sleep 4 | DATA_DIR = './data' 5 | if not os.path.exists(DATA_DIR): 6 | os.makedirs(DATA_DIR) 7 | 8 | number_of_classes = 5 9 | 10 | dataset_size = 10 11 | try: 12 | key = cv2. waitKey(1) 13 | cap = cv2.VideoCapture(0) 14 | sleep(2) 15 | 16 | for j in range(number_of_classes): 17 | if not os.path.exists(os.path.join(DATA_DIR, str(j))): 18 | os.makedirs(os.path.join(DATA_DIR, str(j))) 19 | 20 | print('Collecting data for class {}'.format(j)) 21 | 22 | done = False 23 | while True: 24 | ret, frame = cap.read() 25 | cv2.putText(frame, 'Ready? Press "Q" ! :)', (100, 50), cv2.FONT_HERSHEY_SIMPLEX, 1.3, (0, 255, 0), 3, 26 | cv2.LINE_AA) 27 | cv2.imshow('frame', frame) 28 | if cv2.waitKey(25) == ord('q'): 29 | break 30 | 31 | counter = 0 32 | while counter < dataset_size: 33 | ret, frame = cap.read() 34 | cv2.imshow('frame', frame) 35 | cv2.waitKey(25) 36 | cv2.imwrite(os.path.join(DATA_DIR, str(j), '{}.jpg'.format(counter)), frame) 37 | 38 | counter += 1 39 | cap.release() 40 | cv2.destroyAllWindows() 41 | except Exception as error: 42 | print(error) -------------------------------------------------------------------------------- /create_dataset.py: -------------------------------------------------------------------------------- 1 | import os 2 | import pickle 3 | 4 | import mediapipe as mp 5 | import cv2 6 | import matplotlib.pyplot as plt 7 | mp_hands = mp.solutions.hands 8 | mp_drawing = mp.solutions.drawing_utils 9 | mp_drawing_styles = mp.solutions.drawing_styles 10 | 11 | hands = mp_hands.Hands(static_image_mode=True, min_detection_confidence=0.3) 12 | 13 | DATA_DIR = './data' 14 | 15 | data = [] 16 | labels = [] 17 | for dir_ in os.listdir(DATA_DIR): 18 | for img_path in os.listdir(os.path.join(DATA_DIR, dir_)): 19 | data_aux = [] 20 | 21 | x_ = [] 22 | y_ = [] 23 | 24 | img = cv2.imread(os.path.join(DATA_DIR, dir_, img_path)) 25 | img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) 26 | 27 | results = hands.process(img_rgb) 28 | if results.multi_hand_landmarks: 29 | for hand_landmarks in results.multi_hand_landmarks: 30 | for i in range(len(hand_landmarks.landmark)): 31 | x = hand_landmarks.landmark[i].x 32 | y = hand_landmarks.landmark[i].y 33 | 34 | x_.append(x) 35 | y_.append(y) 36 | 37 | for i in range(len(hand_landmarks.landmark)): 38 | x = hand_landmarks.landmark[i].x 39 | y = hand_landmarks.landmark[i].y 40 | data_aux.append(x - min(x_)) 41 | data_aux.append(y - min(y_)) 42 | 43 | data.append(data_aux) 44 | labels.append(dir_) 45 | 46 | f = open('data.pickle', 'wb') 47 | pickle.dump({'data': data, 'labels': labels}, f) 48 | f.close() -------------------------------------------------------------------------------- /data.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shahana67/Sign-Language-Recognition/5382cec6858fc39f12d11bfad61d28c0c17f73ad/data.pickle -------------------------------------------------------------------------------- /demo.py: -------------------------------------------------------------------------------- 1 | # from cv2 import * 2 | # import time 3 | # import cv2 4 | # cam_port = 0 5 | # cam =cv2.VideoCapture(cam_port) 6 | 7 | # a,image = cam.read() 8 | # cv2.imshow("GeeksForGeeks", image) 9 | # # print(b) 10 | import cv2 11 | from time import sleep 12 | key = cv2. waitKey(1) 13 | webcam = cv2.VideoCapture(0) 14 | sleep(2) 15 | while True: 16 | 17 | try: 18 | check, frame = webcam.read() 19 | print(check) #prints true as long as the webcam is running 20 | print(frame) #prints matrix values of each framecd 21 | cv2.imshow("Capturing", frame) 22 | key = cv2.waitKey(1) 23 | if key == ord('s'): 24 | cv2.imwrite(filename='saved_img.jpg', img=frame) 25 | webcam.release() 26 | print("Processing image...") 27 | img_ = cv2.imread('saved_img.jpg', cv2.IMREAD_ANYCOLOR) 28 | print("Converting RGB image to grayscale...") 29 | gray = cv2.cvtColor(img_, cv2.COLOR_BGR2GRAY) 30 | print("Converted RGB image to grayscale...") 31 | print("Resizing image to 28x28 scale...") 32 | img_ = cv2.resize(gray,(28,28)) 33 | print("Resized...") 34 | img_resized = cv2.imwrite(filename='saved_img-final.jpg', img=img_) 35 | print("Image saved!") 36 | 37 | break 38 | 39 | elif key == ord('q'): 40 | webcam.release() 41 | cv2.destroyAllWindows() 42 | break 43 | 44 | except(KeyboardInterrupt): 45 | print("Turning off camera.") 46 | webcam.release() 47 | print("Camera off.") 48 | print("Program ended.") 49 | cv2.destroyAllWindows() 50 | break -------------------------------------------------------------------------------- /inferance_classifier.py: -------------------------------------------------------------------------------- 1 | import pickle 2 | 3 | import cv2 4 | import mediapipe as mp 5 | import numpy as np 6 | 7 | model_dict = pickle.load(open('./model.p', 'rb')) 8 | model = model_dict['model'] 9 | key = cv2. waitKey(1) 10 | cap = cv2.VideoCapture(0) 11 | 12 | mp_hands = mp.solutions.hands 13 | mp_drawing = mp.solutions.drawing_utils 14 | mp_drawing_styles = mp.solutions.drawing_styles 15 | 16 | hands = mp_hands.Hands(static_image_mode=True, min_detection_confidence=0.3) 17 | 18 | labels_dict = {0: 'Hello',1:'Thank you',2:'Help',3:'1',4:'2'} 19 | while True: 20 | 21 | data_aux = [] 22 | x_ = [] 23 | y_ = [] 24 | 25 | ret, frame = cap.read() 26 | 27 | H, W, _ = frame.shape 28 | 29 | frame_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB) 30 | 31 | results = hands.process(frame_rgb) 32 | if results.multi_hand_landmarks: 33 | for hand_landmarks in results.multi_hand_landmarks: 34 | mp_drawing.draw_landmarks( 35 | frame, # image to draw 36 | hand_landmarks, # model output 37 | mp_hands.HAND_CONNECTIONS, # hand connections 38 | mp_drawing_styles.get_default_hand_landmarks_style(), 39 | mp_drawing_styles.get_default_hand_connections_style()) 40 | 41 | for hand_landmarks in results.multi_hand_landmarks: 42 | for i in range(len(hand_landmarks.landmark)): 43 | x = hand_landmarks.landmark[i].x 44 | y = hand_landmarks.landmark[i].y 45 | 46 | x_.append(x) 47 | y_.append(y) 48 | 49 | for i in range(len(hand_landmarks.landmark)): 50 | x = hand_landmarks.landmark[i].x 51 | y = hand_landmarks.landmark[i].y 52 | data_aux.append(x - min(x_)) 53 | data_aux.append(y - min(y_)) 54 | 55 | x1 = int(min(x_) * W) - 10 56 | y1 = int(min(y_) * H) - 10 57 | 58 | x2 = int(max(x_) * W) - 10 59 | y2 = int(max(y_) * H) - 10 60 | 61 | prediction = model.predict([np.asarray(data_aux)]) 62 | 63 | predicted_character = labels_dict[int(prediction[0])] 64 | 65 | cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 0, 0), 4) 66 | cv2.putText(frame, predicted_character, (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 1.3, (0, 0, 0), 3, 67 | cv2.LINE_AA) 68 | 69 | cv2.imshow('SIGN DETECTOR', frame) 70 | cv2.waitKey(1) 71 | cap.release() 72 | cv2.destroyAllWindows() -------------------------------------------------------------------------------- /model.p: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shahana67/Sign-Language-Recognition/5382cec6858fc39f12d11bfad61d28c0c17f73ad/model.p -------------------------------------------------------------------------------- /train_classifer.py: -------------------------------------------------------------------------------- 1 | # import pickle 2 | 3 | # from sklearn.ensemble import RandomForestClassifier 4 | # from sklearn.model_selection import train_test_split 5 | # from sklearn.metrics import accuracy_score 6 | # import numpy as np 7 | 8 | # try: 9 | # data_dict = pickle.load(open('./data.pickle', 'rb')) 10 | 11 | # data = np.asarray(data_dict['data']) 12 | # labels = np.asarray(data_dict['labels']) 13 | 14 | # x_train, x_test, y_train, y_test = train_test_split([data], labels, test_size=0.2, shuffle=True, stratify=labels) 15 | 16 | # model = RandomForestClassifier() 17 | 18 | # model.fit(x_train, y_train) 19 | 20 | # y_predict = model.predict(x_test) 21 | 22 | # score = accuracy_score(y_predict, y_test) 23 | 24 | # print('{}% of samples were classified correctly !'.format(score * 100)) 25 | 26 | # f = open('model.p', 'wb') 27 | # pickle.dump({'model': model}, f) 28 | # f.close() 29 | # except Exception as e: 30 | # print(e) 31 | import pickle 32 | 33 | from sklearn.ensemble import RandomForestClassifier 34 | from sklearn.model_selection import train_test_split 35 | from sklearn.metrics import accuracy_score 36 | import numpy as np 37 | 38 | 39 | data_dict = pickle.load(open('./data.pickle', 'rb')) 40 | 41 | data = np.asarray(data_dict['data']) 42 | labels = np.asarray(data_dict['labels']) 43 | 44 | x_train, x_test, y_train, y_test = train_test_split(data, labels, test_size=0.5, shuffle=True, stratify=labels) 45 | 46 | model = RandomForestClassifier() 47 | 48 | model.fit(x_train, y_train) 49 | 50 | y_predict = model.predict(x_test) 51 | 52 | score = accuracy_score(y_predict, y_test) 53 | 54 | print('{}% of samples were classified correctly !'.format(score * 100)) 55 | 56 | f = open('model.p', 'wb') 57 | pickle.dump({'model': model}, f) 58 | f.close() 59 | --------------------------------------------------------------------------------