Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def predict(hand):
- img = cv2.resize(hand, (50, 50))
- img = np.array(img)
- img = img.reshape((1, 50, 50, 1))
- img = img / 255.0
- res = model.predict(img)
- while True:
- ret, frame = vc.read()
- frame = cv2.flip(frame, 1)
- cv2.rectangle(frame, (100, 100), (300, 300), (0, 255, 255), 2)
- cv2.imshow("Recording", frame)
- roi = frame[100:300, 100:300]
- roi = cv2.cvtColor(roi, cv2.COLOR_BGR2GRAY)
- blur = cv2.GaussianBlur(roi, (11, 11), 0)
- blur = cv2.medianBlur(blur, 15)
- thresh = cv2.threshold(blur, 210, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
- thresh = cv2.bitwise_not(thresh)
- cv2.imshow("hand", thresh)
- count_frames += 1
- print('Frame: ', count_frames)
- if count_frames == 100:
- old_pred_text = pred_text
- #predict 100th frame
- pred_text = predict(thresh)
- if old_pred_text == pred_text:
- count_frames += 1
- else:
- count_frames = 0
- if count_frames > 20 and pred_text != "":
- tot_string += pred_text + " "
- count_frames = 0
- k = cv2.waitKey(5) & 0xFF
- if k == 27:
- break
Add Comment
Please, Sign In to add comment