Guest User

Untitled

a guest
Nov 20th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. def predict(hand):
  2. img = cv2.resize(hand, (50, 50))
  3. img = np.array(img)
  4. img = img.reshape((1, 50, 50, 1))
  5. img = img / 255.0
  6. res = model.predict(img)
  7.  
  8. while True:
  9. ret, frame = vc.read()
  10. frame = cv2.flip(frame, 1)
  11.  
  12. cv2.rectangle(frame, (100, 100), (300, 300), (0, 255, 255), 2)
  13. cv2.imshow("Recording", frame)
  14.  
  15. roi = frame[100:300, 100:300]
  16.  
  17. roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
  18. blur = cv2.GaussianBlur(roi, (11, 11), 0)
  19. blur = cv2.medianBlur(blur, 15)
  20. thresh = cv2.threshold(blur, 210, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
  21. thresh = cv2.bitwise_not(thresh)
  22. cv2.imshow("hand", thresh)
  23.  
  24. count_frames += 1
  25. print('Frame: ', count_frames)
  26.  
  27. if count_frames == 100:
  28. old_pred_text = pred_text
  29. #predict 100th frame
  30. pred_text = predict(thresh)
  31.  
  32. if old_pred_text == pred_text:
  33. count_frames += 1
  34. else:
  35. count_frames = 0
  36.  
  37. if count_frames > 20 and pred_text != "":
  38. tot_string += pred_text + " "
  39. count_frames = 0
  40.  
  41. k = cv2.waitKey(5) & 0xFF
  42. if k == 27:
  43. break
Add Comment
Please, Sign In to add comment