Skip to content

Mishratanay #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ This project uses python 3.5 and the PIP following packages:
* tensorflow
* matplotlib
* numpy
* gttf
* pygame

See requirements.txt and Dockerfile for versions and required APT packages

Expand Down
4 changes: 2 additions & 2 deletions classify.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@

# Loads label file, strips off carriage return
label_lines = [line.rstrip() for line
in tf.gfile.GFile("logs/output_labels.txt")]
in tf.gfile.GFile("logs/trained_labels.txt")]

# Unpersists graph from file
with tf.gfile.FastGFile("logs/output_graph.pb", 'rb') as f:
with tf.gfile.FastGFile("logs/trained_graph.pb", 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
Expand Down
22 changes: 17 additions & 5 deletions classify_webcam.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
from gtts import gTTS
import sys
import os

import matplotlib
import numpy as np
import matplotlib.pyplot as plt
import copy
import cv2
from pygame import mixer




# Disable tensorflow compilation warnings
os.environ['TF_CPP_MIN_LOG_LEVEL']='2'
Expand All @@ -31,10 +35,10 @@ def predict(image_data):

# Loads label file, strips off carriage return
label_lines = [line.rstrip() for line
in tf.gfile.GFile("logs/output_labels.txt")]
in tf.gfile.GFile("logs/trained_labels.txt")]

# Unpersists graph from file
with tf.gfile.FastGFile("logs/output_graph.pb", 'rb') as f:
with tf.gfile.FastGFile("logs/trained_graph.pb", 'rb') as f:
graph_def = tf.GraphDef()
graph_def.ParseFromString(f.read())
_ = tf.import_graph_def(graph_def, name='')
Expand All @@ -52,6 +56,7 @@ def predict(image_data):
mem = ''
consecutive = 0
sequence = ''
final =''

while True:
ret, img = cap.read()
Expand All @@ -76,7 +81,14 @@ def predict(image_data):
consecutive = 0
if consecutive == 2 and res not in ['nothing']:
if res == 'space':
sequence += ' '
tts = gTTS(text=sequence, lang='en')
tts.save("test.mp3")

mixer.init()
mixer.music.load('test.mp3')
mixer.music.play()
final = final + sequence
sequence=' '
elif res == 'del':
sequence = sequence[:-1]
else:
Expand All @@ -89,7 +101,7 @@ def predict(image_data):
cv2.rectangle(img, (x1, y1), (x2, y2), (255,0,0), 2)
cv2.imshow("img", img)
img_sequence = np.zeros((200,1200,3), np.uint8)
cv2.putText(img_sequence, '%s' % (sequence.upper()), (30,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
cv2.putText(img_sequence, '%s' % (final.upper()), (30,30), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
cv2.imshow('sequence', img_sequence)

if a == 27: # when `esc` is pressed
Expand Down
4 changes: 3 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
tensorflow==1.2.1
matplotlib==2.0.2
numpy==1.13.0
opencv-python==3.2.0.8
opencv-python==3.2.0.8
pygame
gtts