├── ASL Recognition.docx ├── Letters_stash_for_sounds ├── B.txt ├── D.txt ├── H.txt ├── I.txt ├── J.txt ├── U.txt ├── Y.txt ├── A.mp3 ├── A.txt ├── A.txt~ ├── B.mp3 ├── B.txt ├── B.txt~ ├── C.mp3 ├── C.txt ├── C.txt~ ├── CALIBRATE.mp3 ├── CALIBRATE.txt ├── D.mp3 ├── D.txt ├── F.mp3 ├── F.txt ├── G.mp3 ├── H.mp3 ├── H.txt ├── I.mp3 ├── I.txt ├── J.mp3 ├── J.txt ├── L.mp3 ├── L.txt ├── U.mp3 ├── U.txt ├── V.mp3 ├── V.txt ├── V.txt~ ├── W.mp3 ├── W.txt ├── Y.mp3 ├── Y.txt ├── dummy.txt ├── instructions.mp3 └── welcome.mp3 ├── README.md ├── final.py └── ultimate.sh /ASL Recognition.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/ASL Recognition.docx -------------------------------------------------------------------------------- /Letters_stash_for_sounds/ B.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Letters_stash_for_sounds/ D.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Letters_stash_for_sounds/ H.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Letters_stash_for_sounds/ I.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Letters_stash_for_sounds/ J.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Letters_stash_for_sounds/ U.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Letters_stash_for_sounds/ Y.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Letters_stash_for_sounds/A.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/A.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/A.txt: -------------------------------------------------------------------------------- 1 | A -------------------------------------------------------------------------------- /Letters_stash_for_sounds/A.txt~: -------------------------------------------------------------------------------- 1 | A -------------------------------------------------------------------------------- /Letters_stash_for_sounds/B.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/B.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/B.txt: -------------------------------------------------------------------------------- 1 | B -------------------------------------------------------------------------------- /Letters_stash_for_sounds/B.txt~: -------------------------------------------------------------------------------- 1 | B -------------------------------------------------------------------------------- /Letters_stash_for_sounds/C.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/C.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/C.txt: -------------------------------------------------------------------------------- 1 | C -------------------------------------------------------------------------------- /Letters_stash_for_sounds/C.txt~: -------------------------------------------------------------------------------- 1 | C -------------------------------------------------------------------------------- /Letters_stash_for_sounds/CALIBRATE.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/CALIBRATE.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/CALIBRATE.txt: -------------------------------------------------------------------------------- 1 | CALIBRATE -------------------------------------------------------------------------------- /Letters_stash_for_sounds/D.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/D.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/D.txt: -------------------------------------------------------------------------------- 1 | D -------------------------------------------------------------------------------- /Letters_stash_for_sounds/F.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/F.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/F.txt: -------------------------------------------------------------------------------- 1 | F -------------------------------------------------------------------------------- /Letters_stash_for_sounds/G.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/G.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/H.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/H.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/H.txt: -------------------------------------------------------------------------------- 1 | H -------------------------------------------------------------------------------- /Letters_stash_for_sounds/I.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/I.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/I.txt: -------------------------------------------------------------------------------- 1 | I -------------------------------------------------------------------------------- /Letters_stash_for_sounds/J.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/J.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/J.txt: -------------------------------------------------------------------------------- 1 | J -------------------------------------------------------------------------------- /Letters_stash_for_sounds/L.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/L.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/L.txt: -------------------------------------------------------------------------------- 1 | L -------------------------------------------------------------------------------- /Letters_stash_for_sounds/U.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/U.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/U.txt: -------------------------------------------------------------------------------- 1 | U -------------------------------------------------------------------------------- /Letters_stash_for_sounds/V.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/V.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/V.txt: -------------------------------------------------------------------------------- 1 | V -------------------------------------------------------------------------------- /Letters_stash_for_sounds/V.txt~: -------------------------------------------------------------------------------- 1 | V d 2 | -------------------------------------------------------------------------------- /Letters_stash_for_sounds/W.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/W.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/W.txt: -------------------------------------------------------------------------------- 1 | W -------------------------------------------------------------------------------- /Letters_stash_for_sounds/Y.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/Y.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/Y.txt: -------------------------------------------------------------------------------- 1 | Y -------------------------------------------------------------------------------- /Letters_stash_for_sounds/dummy.txt: -------------------------------------------------------------------------------- 1 | dummy -------------------------------------------------------------------------------- /Letters_stash_for_sounds/instructions.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/instructions.mp3 -------------------------------------------------------------------------------- /Letters_stash_for_sounds/welcome.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AnupamYedida/Sign_Language_Recognition/feeaf05419235c19dd6313080cf4d14e0916f564/Letters_stash_for_sounds/welcome.mp3 -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Sign-Language-Recognition- 2 | American Sign Language Recognition using Python ( With multiple outputs) , OpenCV 3 | 4 | Just run the python script with an input argumen of either "1" or "0" depending on the number of your webcam. So it will be like this -----> python final.py 1 or python final.py 0 5 | 6 | Then run the bash scipt in the backround in another terminal . 7 | 8 | Video Of the project can be found at the link : https://www.youtube.com/watch?v=1BD5C_B2o5Y&t=51s 9 | 10 | Please feel free to ask any questions @ anupamy@gmail.com. 11 | -------------------------------------------------------------------------------- /final.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import numpy as np 3 | import math 4 | import sys 5 | import pygame 6 | import time 7 | import os 8 | import subprocess 9 | import pyglet 10 | import Tkinter 11 | from Tkinter import * 12 | from os import path 13 | from Tkinter import Tk, Frame, BOTH 14 | from PIL import Image, ImageTk 15 | 16 | k = cv2.waitKey(10) & 0xFF 17 | 18 | 19 | song = pyglet.media.load('instructions.mp3') 20 | 21 | 22 | 23 | root = Tk() 24 | root.title("ASL Translator Application") 25 | 26 | 27 | 28 | 29 | 30 | 31 | im = Image.open('ASL.jpg') 32 | tkimage = ImageTk.PhotoImage(im) 33 | myvar=Tkinter.Label(root,image = tkimage) 34 | myvar.place(relx=0.5, rely=0.735, anchor=CENTER) 35 | 36 | 37 | 38 | 39 | # Shell Scripting Command Execution -------------------------------------------------------------------------------- 40 | cmd = "ultimate.sh" 41 | 42 | 43 | 44 | 45 | def call_back(): 46 | print "Button Pressed!" 47 | song.play() 48 | #pyglet.app.run() 49 | 50 | 51 | def final_callback(): 52 | 53 | """ 54 | """ 55 | 56 | 57 | 58 | def exit(): 59 | 60 | 61 | root.destroy() 62 | 63 | 64 | 65 | def main(): 66 | #subprocess.Popen(["bash", "ultimate.sh"]) 67 | 68 | 69 | 70 | 71 | pygame.init() 72 | song = pygame.mixer.Sound('A.wav') 73 | clock = pygame.time.Clock() 74 | 75 | sound_tick = 0 76 | 77 | var_A = 0 78 | 79 | 80 | # Testing Bash Script in python 81 | 82 | #subprocess.call("test_bash.sh") 83 | 84 | 85 | def createFile(dest): 86 | name = letter_correspond 87 | if not(path.isfile(dest + name)): 88 | f = open(dest + name,'w') 89 | f.write('\n'*5) 90 | f.close() 91 | 92 | 93 | 94 | 95 | 96 | 97 | co_ordinates_for_CONVEX_HULL = [[]] 98 | abc = [] 99 | 100 | 101 | 102 | 103 | font = cv2.FONT_HERSHEY_SIMPLEX 104 | put_text_color = (18,0,255) 105 | put_text_pos = (60,50) 106 | 107 | 108 | 109 | lower_thresh1 = 129 110 | upper_thresh1 = 255 111 | 112 | j = 0 113 | PI = math.pi 114 | 115 | 116 | """img_test = cv2.imread("1.jpg",0) 117 | ret_1,thresh_test = cv2.threshold(img_test,125,255,0) 118 | xyz_test,contours_test,hierarchy_test = cv2.findContours(thresh_test,2,1) 119 | cnt_test_yo = [4] 120 | ret_1 = cv2.matchShapes(cnt_test_yo,cnt,1,0.0) 121 | print ret_1""" 122 | 123 | 124 | #letter_I_match_shape = cv2.imread('I.jpg',0) 125 | 126 | camera_index = int(sys.argv[1]) 127 | cap = cv2.VideoCapture(camera_index) 128 | 129 | 130 | 131 | 132 | 133 | 134 | while(cap.isOpened()): 135 | 136 | 137 | 138 | 139 | img_dofh = cv2.imread("D.png",0) 140 | ret, img = cap.read() 141 | cv2.rectangle(img,(60,60),(300,300),(255,255,2),4) #outer most rectangle 142 | crop_img = img[70:300, 70:300] 143 | crop_img_2 = img[70:300, 70:300] 144 | 145 | grey = cv2.cvtColor(crop_img, cv2.COLOR_BGR2GRAY) 146 | 147 | #edges = cv2.Canny(crop_img,100,200) 148 | 149 | 150 | 151 | ############################### Corners Detection 152 | 153 | 154 | hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) 155 | 156 | lower_red = np.array([0,150,50]) 157 | 158 | 159 | upper_red = np.array([195,255,255]) 160 | 161 | 162 | 163 | 164 | 165 | mask = cv2.inRange(hsv, lower_red, upper_red) 166 | res = cv2.bitwise_and(img,img, mask= mask) 167 | 168 | 169 | 170 | 171 | value = (35, 35) 172 | blurred = cv2.GaussianBlur(grey, value, 0) 173 | _, thresh1 = cv2.threshold(blurred, lower_thresh1, upper_thresh1, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) 174 | _, thresh_dofh = cv2.threshold(img_dofh, lower_thresh1, upper_thresh1, cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) 175 | #defrt,thresh_for_I = cv2.threshold(letter_I_match_shape,125,255,0) 176 | 177 | 178 | 179 | xyz,contours, hierarchy = cv2.findContours(thresh1.copy(),cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) 180 | xyz,contours_dofh, hierarchy_dofh = cv2.findContours(thresh_dofh,2,1) 181 | #cnt_dofh = contours_dofh[1] 182 | 183 | cnt = max(contours, key = lambda x: cv2.contourArea(x)) 184 | #cnt_m = contours[0] 185 | #print cnt_m 186 | area_of_contour = cv2.contourArea(cnt) 187 | 188 | x,y,w,h = cv2.boundingRect(cnt) 189 | cv2.rectangle(crop_img,(x,y),(x+w,y+h),(0,0,255),1) # Red Rectangle 190 | #ratio_of_red_rect = h/w 191 | #print ratio_of_red_rect 192 | 193 | hull = cv2.convexHull(cnt) 194 | drawing = np.zeros(crop_img.shape,np.uint8) 195 | 196 | cv2.drawContours(drawing,[cnt],0,(0,255,0),0) 197 | cv2.drawContours(drawing,[hull],0,(0,255,255),0) 198 | 199 | hull = cv2.convexHull(cnt,returnPoints = False) 200 | #co_ordinates_for_CONVEX_HULL = cv2.convexHull(cnt,returnPoints = True) 201 | defects = cv2.convexityDefects(cnt,hull) 202 | 203 | 204 | 205 | count_defects = 0 206 | cv2.drawContours(thresh1, contours, -1, (0,255,0), 3) 207 | 208 | for i in range(defects.shape[0]): 209 | s,e,f,d = defects[i,0] 210 | start = tuple(cnt[s][0]) 211 | end = tuple(cnt[e][0]) 212 | far = tuple(cnt[f][0]) 213 | 214 | 215 | a = math.sqrt((end[0] - start[0])**2 + (end[1] - start[1])**2) 216 | b = math.sqrt((far[0] - start[0])**2 + (far[1] - start[1])**2) 217 | c = math.sqrt((end[0] - far[0])**2 + (end[1] - far[1])**2) 218 | 219 | 220 | 221 | angle = math.acos((b**2 + c**2 - a**2)/(2*b*c)) * 60 222 | cv2.circle(crop_img,far,4,[0,0,255],-1) # Red Circles###########################3 223 | #cv2.line(crop_img,start,end,[255,255,0],2) 224 | 225 | 226 | if angle <= 90: 227 | count_defects += 1 228 | #yeyo = cv2.circle(crop_img,far,1,[255,0,0],-1) 229 | 230 | 231 | cv2.line(crop_img,start,end,[0,255,0],3) 232 | 233 | 234 | moment = cv2.moments(cnt) 235 | perimeter = cv2.arcLength(cnt,True) 236 | area = cv2.contourArea(cnt) 237 | 238 | 239 | (x,y),radius = cv2.minEnclosingCircle(cnt) 240 | center = (int(x),int(y)) 241 | radius = int(radius) 242 | cv2.circle(crop_img,center,radius,(255,0,0),2) 243 | 244 | area_of_circle=PI*radius*radius 245 | 246 | 247 | 248 | hull_test = cv2.convexHull(cnt) 249 | hull_area = cv2.contourArea(hull_test) 250 | solidity = float(area)/hull_area 251 | 252 | 253 | aspect_ratio = float(w)/h 254 | 255 | rect_area = w*h 256 | extent = float(area)/rect_area 257 | 258 | (x,y),(MA,ma),angle_t = cv2.fitEllipse(cnt) 259 | 260 | #ret_1 = cv2.matchShapes(cnt,contours_dofh,1,0.0) 261 | #print ret_1 262 | 263 | 264 | 265 | if area_of_circle - area < 5000: 266 | 267 | 268 | 269 | 270 | 271 | letter_correspond = "A.txt" 272 | 273 | destination ='Letters_stash_for_sounds/' 274 | createFile(destination) 275 | #raw_input("done!!!") 276 | 277 | output = "A" 278 | outFile = open('Letters_stash_for_sounds/A.txt', 'w') 279 | outFile.write(output) 280 | 281 | cv2.putText(img, "The Letter is : A (CALIBRATED)", put_text_pos, font, 1 , put_text_color, 2, cv2.LINE_AA) 282 | #cv2.putText(img, "The letter is :", (60,50), font, 1 , put_text_color, 2, cv2.LINE_AA) 283 | #cv2.putText(img, "A", (320,55), font, 2 , (50,100,190), 3, cv2.LINE_AA) 284 | 285 | elif count_defects ==1: 286 | 287 | if angle_t < 10: 288 | 289 | 290 | letter_correspond = "V.txt" 291 | 292 | destination ='Letters_stash_for_sounds/' 293 | createFile(destination) 294 | #raw_input("done!!!") 295 | 296 | output = "V" 297 | outFile = open('Letters_stash_for_sounds/V.txt', 'w') 298 | outFile.write(output) 299 | 300 | #letter_correspond = "V.txt" 301 | 302 | 303 | cv2.putText(img, "The Letter is : V", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 304 | 305 | elif 40 < angle_t < 66: 306 | 307 | 308 | 309 | letter_correspond = "C.txt" 310 | 311 | destination ='Letters_stash_for_sounds/' 312 | createFile(destination) 313 | #raw_input("done!!!") 314 | 315 | output = "C" 316 | outFile = open('Letters_stash_for_sounds/C.txt', 'w') 317 | outFile.write(output) 318 | 319 | 320 | cv2.putText(img, "The Letter is : C", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 321 | 322 | elif 20 < angle_t < 35: 323 | 324 | 325 | letter_correspond = "L.txt" 326 | 327 | destination ='Letters_stash_for_sounds/' 328 | createFile(destination) 329 | #raw_input("done!!!") 330 | 331 | output = "L" 332 | outFile = open('Letters_stash_for_sounds/L.txt', 'w') 333 | outFile.write(output) 334 | 335 | 336 | cv2.putText(img, "The Letter is : L", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 337 | 338 | 339 | 340 | else: 341 | 342 | 343 | 344 | 345 | 346 | letter_correspond = "Y.txt" 347 | 348 | destination ='Letters_stash_for_sounds/' 349 | createFile(destination) 350 | #raw_input("done!!!") 351 | 352 | output = "Y" 353 | outFile = open('Letters_stash_for_sounds/Y.txt', 'w') 354 | outFile.write(output) 355 | 356 | cv2.putText(img,"The Letter is : Y", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 357 | 358 | 359 | 360 | 361 | #print "Its 2" 362 | elif count_defects == 2: # Its either W or F 363 | 364 | if angle_t > 100: 365 | 366 | letter_correspond = "F.txt" 367 | 368 | destination ='Letters_stash_for_sounds/' 369 | createFile(destination) 370 | #raw_input("done!!!") 371 | 372 | output = "F" 373 | outFile = open('Letters_stash_for_sounds/F.txt', 'w') 374 | outFile.write(output) 375 | 376 | cv2.putText(img, "The Letter is : F", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 377 | 378 | else: 379 | 380 | letter_correspond = "W.txt" 381 | 382 | destination ='Letters_stash_for_sounds/' 383 | createFile(destination) 384 | #raw_input("done!!!") 385 | 386 | output = "W" 387 | outFile = open('Letters_stash_for_sounds/W.txt', 'w') 388 | outFile.write(output) 389 | 390 | cv2.putText(img, "The Letter is : W", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 391 | 392 | elif count_defects == 4: 393 | 394 | 395 | 396 | 397 | 398 | letter_correspond = "CALIBRATE.txt" 399 | 400 | destination ='Letters_stash_for_sounds/' 401 | createFile(destination) 402 | #raw_input("done!!!") 403 | 404 | output = "CALIBRATE" 405 | outFile = open('Letters_stash_for_sounds/CALIBRATE.txt', 'w') 406 | outFile.write(output) 407 | 408 | 409 | cv2.putText(img,"Hello There ! Callibrate by letter A", put_text_pos, font,1, put_text_color, 2, cv2.LINE_AA) 410 | 411 | 412 | 413 | else: 414 | if area > 12000: 415 | 416 | 417 | letter_correspond = " B.txt" 418 | 419 | destination ='Letters_stash_for_sounds/' 420 | createFile(destination) 421 | #raw_input("done!!!") 422 | 423 | output = "B" 424 | outFile = open('Letters_stash_for_sounds/B.txt', 'w') 425 | outFile.write(output) 426 | 427 | cv2.putText(img,"The Letter is : B", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 428 | 429 | else: 430 | 431 | if solidity < 0.85: 432 | 433 | 434 | if aspect_ratio < 1: 435 | 436 | if angle_t < 20: 437 | 438 | letter_correspond = " D.txt" 439 | 440 | destination ='Letters_stash_for_sounds/' 441 | createFile(destination) 442 | #raw_input("done!!!") 443 | 444 | output = "D" 445 | outFile = open('Letters_stash_for_sounds/D.txt', 'w') 446 | outFile.write(output) 447 | 448 | cv2.putText(img,"The Letter is : D", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 449 | 450 | elif 169 1.01: 485 | 486 | letter_correspond = " Y.txt" 487 | 488 | destination ='Letters_stash_for_sounds/' 489 | createFile(destination) 490 | #raw_input("done!!!") 491 | 492 | output = "Y" 493 | outFile = open('Letters_stash_for_sounds/Y.txt', 'w') 494 | outFile.write(output) 495 | 496 | cv2.putText(img,"The Letter is : Y", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 497 | 498 | 499 | else: 500 | 501 | if angle_t > 30 and angle_t < 100: 502 | 503 | letter_correspond = " H.txt" 504 | 505 | destination ='Letters_stash_for_sounds/' 506 | createFile(destination) 507 | #raw_input("done!!!") 508 | 509 | output = "H" 510 | outFile = open('Letters_stash_for_sounds/H.txt', 'w') 511 | outFile.write(output) 512 | 513 | cv2.putText(img,"The Letter is : H", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 514 | 515 | 516 | 517 | 518 | 519 | elif angle_t > 120: 520 | 521 | 522 | 523 | 524 | 525 | letter_correspond = " I.txt" 526 | 527 | destination ='Letters_stash_for_sounds/' 528 | createFile(destination) 529 | #raw_input("done!!!") 530 | 531 | output = "I" 532 | outFile = open('Letters_stash_for_sounds/I.txt', 'w') 533 | outFile.write(output) 534 | 535 | cv2.putText(img,"The Letter is : I", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) 536 | 537 | 538 | 539 | else: 540 | 541 | letter_correspond = " U.txt" 542 | 543 | destination ='Letters_stash_for_sounds/' 544 | createFile(destination) 545 | #raw_input("done!!!") 546 | 547 | output = "U" 548 | outFile = open('Letters_stash_for_sounds/U.txt', 'w') 549 | outFile.write(output) 550 | 551 | cv2.putText(img,"The Letter is : U", put_text_pos, font, 1, put_text_color, 2, cv2.LINE_AA) # 552 | 553 | 554 | 555 | #crop_img[dst>0.01*dst.max()]=[255,0,0] 556 | cv2.imshow('Gesture', img) 557 | cv2.imshow('Contours', drawing) 558 | cv2.imshow('Defects', crop_img) 559 | cv2.imshow('Binary Image', thresh1) 560 | 561 | 562 | 563 | 564 | 565 | # Testing Parameters : 566 | 567 | #print co_ordinates_for_CONVEX_HULL 568 | #print abc 569 | #cv2.imshow('something',yeyo) 570 | #print area_of_contour,co_ordinates_for_CONVEX_HULL 571 | #print moment 572 | print "Perimeter is :" ,perimeter 573 | #print "The area is:", area 574 | #print defects 575 | #print crop_img.shape 576 | #print defects.shape 577 | #print dist_from_farthest 578 | #print count_defectsd 579 | #print hull 580 | #print far 581 | #print equi_diameter 582 | print 'Radius:',PI*radius*radius ,"Area:", area 583 | print area_of_circle - area 584 | print "The solidity is:" ,solidity 585 | print "The aspect ratio is :", aspect_ratio 586 | print "The number of convexity defects are :",count_defects 587 | print "The extent is :",extent 588 | print "the angle is:", angle_t 589 | print '\033[91m'+"The area of effective circle is " +'\033[0m',area_of_circle - area 590 | 591 | 592 | 593 | 594 | """ 595 | img1 = cv2.imread('match_shapes_test.png',0) 596 | #img2 = cv2.imread(thresh1,0) 597 | 598 | ret, thresh_8 = cv2.threshold(img1, 127, 255,0) 599 | ret, thresh_9 = cv2.threshold(thresh1, 127, 255,0) 600 | xcv,contours_8,hierarchy = cv2.findContours(thresh_8,2,1) 601 | cnt1 = contours_8[0] 602 | vbgf,contours_9,hierarchy = cv2.findContours(thresh_9,2,1) 603 | cnt_9 = max(contours_9, key = lambda s: cv2.contourArea(s)) 604 | 605 | ret = cv2.matchShapes(cnt1,cnt_9,1,0.0) 606 | print "The probability is :",ret """ 607 | 608 | 609 | k = cv2.waitKey(10) & 0xFF 610 | 611 | 612 | 613 | #if k == ord('s'): 614 | # cv2.imwrite('testing_match.png',crop_img_2) 615 | 616 | if k == ord('s'): 617 | 618 | os.system("gnome-terminal -e 'bash -c \"bash ultimate.sh; exec bash\"'") 619 | pid = os.getpid() 620 | 621 | 622 | elif k == 27 or k == ord('q') : 623 | 624 | 625 | break 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | ###################################################################################################################################### 635 | w = Label(root,text="Press the button below if you want to Listen to the instructions.") 636 | w.config(width=75) 637 | w.config(font=("Helvetica", 30)) 638 | w.pack() 639 | 640 | 641 | b1 = Button(root, text="Instructions",command=call_back,bg="lightgreen") 642 | b1.config(font=("Times New Roman", 35,"bold")) 643 | b1.pack() 644 | 645 | x = Label(root,text="Press the button below to run the application (Then,press s for sound).") 646 | x.config(width=75) 647 | x.config(font=("Helvetica", 30)) 648 | x.pack() 649 | 650 | 651 | b2 = Button(root, text="Run",command=main,bg="gold1") 652 | b2.config(font=("Times New Roman", 35,"bold")) 653 | b2.pack() 654 | 655 | 656 | 657 | z = Label(root,text="Press ESCAPE and then the button below to exit.") 658 | z.config(width=75) 659 | z.config(font=("Helvetica", 30)) 660 | z.pack() 661 | 662 | 663 | b3 = Button(root, text="Exit",command=exit,bg="salmon") 664 | b3.config(font=("Raavi", 35,"bold")) 665 | b3.pack() 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | root.mainloop() 674 | -------------------------------------------------------------------------------- /ultimate.sh: -------------------------------------------------------------------------------- 1 | cd Letters_stash_for_sounds/ 2 | 3 | 4 | sleep 2 5 | 6 | while true ; do 7 | 8 | yo=$(ls -Art | tail -n1) 9 | 10 | 11 | 12 | 13 | if [ "$yo" == "A.txt" ]; then 14 | echo The Letter is A 15 | play A.mp3 16 | sleep 2 17 | 18 | 19 | elif [ "$yo" == "B.txt" ]; then 20 | echo The Letter is B 21 | play B.mp3 22 | sleep 2 23 | 24 | 25 | 26 | elif [ "$yo" == "D.txt" ]; then 27 | echo The Letter is D 28 | play D.mp3 29 | sleep 2 30 | 31 | 32 | elif [ "$yo" == "F.txt" ]; then 33 | echo The Letter is F 34 | play F.mp3 35 | sleep 2 36 | 37 | 38 | elif [ "$yo" == "H.txt" ]; then 39 | echo The Letter is H 40 | play H.mp3 41 | sleep 2 42 | 43 | 44 | elif [ "$yo" == "I.txt" ]; then 45 | echo The Letter is I 46 | play I.mp3 47 | sleep 2 48 | 49 | 50 | elif [ "$yo" == "B.txt" ]; then 51 | echo The Letter is B 52 | play B.mp3 53 | sleep 2 54 | 55 | 56 | elif [ "$yo" == "L.txt" ]; then 57 | echo The Letter is L 58 | play L.mp3 59 | sleep 2 60 | 61 | 62 | 63 | elif [ "$yo" == "U.txt" ]; then 64 | echo The Letter is U 65 | play U.mp3 66 | sleep 2 67 | 68 | 69 | 70 | elif [ "$yo" == "V.txt" ]; then 71 | echo The Letter is V 72 | play V.mp3 73 | sleep 2 74 | 75 | 76 | elif [ "$yo" == "W.txt" ]; then 77 | echo The Letter is W 78 | play W.mp3 79 | sleep 2 80 | 81 | 82 | 83 | elif [ "$yo" == "Y.txt" ]; then 84 | echo The Letter is Y 85 | play Y.mp3 86 | sleep 2 87 | 88 | 89 | elif [ "$yo" == "CALIBRATE.txt" ]; then 90 | echo Its Calibrated 91 | play CALIBRATE.mp3 92 | sleep 2 93 | 94 | 95 | elif [ "$yo" == "C.txt" ]; then 96 | echo The Letter is C 97 | play C.mp3 98 | sleep 2 99 | 100 | 101 | 102 | elif [ "$yo" == "J.txt" ]; then 103 | echo The Letter is J 104 | play J.mp3 105 | sleep 2 106 | 107 | 108 | fi 109 | 110 | 111 | done 112 | 113 | 114 | 115 | 116 | 117 | 118 | --------------------------------------------------------------------------------