-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
88 lines (77 loc) · 2.9 KB
/
app.py
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
# Uncomment these lines to see all the messages
# from kivy.logger import Logger
# import logging
# Logger.setLevel(logging.TRACE)
from PIL import Image as pi
from PIL import ImageFilter
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.image import Image
from kivy.clock import Clock
from kivy.graphics.texture import Texture
from kivy.uix.label import Label
import os
import cv2
import numpy as np
import time
import to_detect as tda
class camera_activity(App):
def build(self):
e = CameraClick()
Clock.schedule_interval(e.iniciar, 0.02)
return e
class CameraClick(BoxLayout):
cap = cv2.VideoCapture(0)
cap.read()
CODIGO = 'fitec'
item = 'PLACA'
texto=''
img=None
texture1=None
at =True
def atualizaImagem(self, dt):
try:
if (self.texto.lower().rfind(self.CODIGO.lower())!=-1):
self.ids.label.text = '\t TEXTO '+self.CODIGO.upper()+' ENCONTRADO!'
self.ids.img.texture = self.texture1
self.ids.box.disabled = False
self.ids.box.opacity = 100
else:
ret, frame = self.cap.read()
self.ids.label.text = 'Procurando'
if ret:
self.img,self.texto = tda.load(frame)
self.ids.box.disabled = True
self.ids.box.opacity = 0
self.ids.label.text += '.'
buf1 = cv2.flip(self.img, 0)
buf = buf1.tostring()
self.texture1 = Texture.create(size=(frame.shape[1], frame.shape[0]), colorfmt='bgr')
self.texture1.blit_buffer(buf, colorfmt='bgr', bufferfmt='ubyte')
self.ids.img.texture = self.texture1
## Preparação prar aplicar novos filtros
#m2 = pi.open('images/placa.jpg')
#m2 = m2.filter(ImageFilter.SHARPEN)
#m2.save('placa2.jpg')
except:
print("[ERRO] Capture error")
self.ids.label.text += '...'
time.sleep(0.5)
def iniciar(self,lixo):
if self.at:
if(len(self.ids.label.text)<120):
self.ids.label.text += '|'
else:
self.ids.label.text = 'Pronto!'
self.at=False
Clock.schedule_interval(self.atualizaImagem, 0.01)
def save(self):
timestr = time.strftime("%Y%m%d_%H%M%S")
if not os.path.exists('captures'):
os.mkdir('captures')
cv2.imwrite("captures/{}-{}_{}.jpg".format(self.item,self.CODIGO,timestr),self.img)
self.texto = ''
def repeat(self):
self.texto = ''
camera_activity().run()