forked from Dot-soft-lorca/lorca
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlorca.py
More file actions
114 lines (101 loc) · 2.92 KB
/
lorca.py
File metadata and controls
114 lines (101 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2015 Sergio Carlón Ruiz - All rights reserved
########################################################################
# #
# HackForGood2015 #
# #
# LORCA -no el pueblo, ni el poeta; sino el PROYECTO #
# #
########################################################################
import os
import sys
import numpy as np
import cv2
import copy
from matplotlib import pyplot as plt
import time
import thread
webcam =0
quit_button= 'q'
LANGUAGE = "spa"
ocupado = True
mask = None
def syscall(command):
f = os.popen(command)
response = f.read()
return response
def image_to_text(image):
text_response = syscall("tesseract "+ image +" stdout -l "+LANGUAGE)
clean_text = text_response.replace("\n", " ")
return clean_text
def aplanador(text):
text = text.replace("á","a")
text = text.replace("é","e")
text = text.replace("í","i")
text = text.replace("ó","o")
text = text.replace("ú","u")
text = text.replace("Á","A")
text = text.replace("É","E")
text = text.replace("Í","I")
text = text.replace("Ó","O")
text = text.replace("Ú","u")
text = text.replace("ñ","ni")
text = text.replace("¿","")
text = text.replace("?","")
text = text.replace("!","")
text = text.replace("¡","")
text = text.replace(">","")
text = text.replace("<","")
text = text.replace("`","")
text = text.replace("'","")
text = text.replace("'","")
return text
def use_festival(text):
fich = file("leer","w")
text=aplanador(text)
print "A leer: "+text
fich.write(text)
fich.close()
syscall("cat leer | festival --tts --language spanish")
def collect_words():
global mask
global ocupado
while True:
time.sleep(3)
cv2.imwrite('img.png',mask)
ocupado = True
read_collected_word()
ocupado = False
def read_collected_word ():
text = image_to_text("img.png")
use_festival(text)
def video_window():
global ocupado
global mask
cap = cv2.VideoCapture(webcam)
x=150
y=200
x1=350
y1=75
while(True):
# Capture frame-by-frame
zret, frame = cap.read()
captura=frame.copy()
#rectangulo
if ocupado == True:
cv2.rectangle(frame,(x,y),(x+x1,y+y1),(0,0,255),2)
else:
cv2.rectangle(frame,(x,y),(x+x1,y+y1),(0,255,0),2)
#mascara
captura=cv2.cvtColor(captura, cv2.COLOR_BGR2GRAY)
mask = np.zeros(captura.shape,np.uint8)
mask[y:y+y1,x:x+x1] = captura[y:y+y1,x:x+x1]
# Display the resulting frame
cv2.imshow('frame',frame)
if cv2.waitKey(1) & 0xFF == ord(quit_button):
break
thread.start_new_thread(collect_words, tuple())
video_window()
#text_to_read = image_to_text(sys.argv[1])
#use_festival(text_to_read)