Guest User

Untitled

a guest
Dec 15th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. Traceback <most recent call last>:
  2. File "ASL.py", line 24, in <module>
  3. img1=img[100:500, 900:1300]
  4. TypeError: 'NoneType' object has no attribute '__getitem__'
  5.  
  6. import cv2
  7. import numpy as np
  8. import util as ut
  9. import svm_train as st
  10. import re
  11. model=st.trainSVM(17)
  12. #create and train SVM model each time coz bug in opencv 3.1.0 svm.load() https://github.com/Itseez/opencv/issues/4969
  13. cam=int(raw_input("Enter Camera number: "))
  14. cap=cv2.VideoCapture(cam)
  15. font = cv2.FONT_HERSHEY_SIMPLEX
  16.  
  17. def nothing(x) :
  18. pass
  19.  
  20. text= " "
  21.  
  22. temp=0
  23. previouslabel=None
  24. previousText=" "
  25. label = [None]
  26. while(cap.isOpened()):
  27. _,img=cap.read()
  28. cv2.rectangle(img,(900,100),(1300,500),(255,0,0),3)
  29. img1=img[100:500, 900:1300]
  30. img_ycrcb = cv2.cvtColor(img1, cv2.COLOR_BGR2YCR_CB)
  31. blur = cv2.GaussianBlur(img_ycrcb,(11,11),0)
  32. skin_ycrcb_min = np.array((0, 138, 67))
  33. skin_ycrcb_max = np.array((255, 183, 133))
  34. mask = cv2.inRange(blur, skin_ycrcb_min, skin_ycrcb_max) # detecting the hand in the bounding box using skin detection
  35. contours,hierarchy = cv2.findContours(mask.copy(),cv2.RETR_EXTERNAL, 2)
  36. cnt=ut.getMaxContour(contours,4000) # using contours to capture the skin filtered image of the hand
  37. if cnt!=None:
  38. gesture,label=ut.getGestureImg(cnt,img1,mask,model) # passing the trained model for prediction and fetching the result
  39. if(label!=None):
  40. if(temp==0):
  41. previouslabel=label
  42. if previouslabel==label :
  43. previouslabel=label
  44. temp+=1
  45. else :
  46. temp=0
  47. if(temp==40):
  48. if(label=='P'):
  49.  
  50. label=" "
  51. text= text + label
  52. if(label=='Q'):
  53. words = re.split(" +",text)
  54. words.pop()
  55. text = " ".join(words)
  56. #text=previousText
  57. print text
  58.  
  59. cv2.imshow('PredictedGesture',gesture) # showing the best match or prediction
  60. cv2.putText(img,label,(50,150), font,8,(0,125,155),2) # displaying the predicted letter on the main screen
  61. cv2.putText(img,text,(50,450), font,3,(0,0,255),2)
  62. cv2.imshow('Frame',img)
  63. cv2.imshow('Mask',mask)
  64. k = 0xFF & cv2.waitKey(10)
  65. if k == 27:
  66. break
  67.  
  68.  
  69. cap.release()
  70. cv2.destroyAllWindows()
Add Comment
Please, Sign In to add comment