-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathScreenVirtualButtons.py
71 lines (53 loc) · 1.93 KB
/
ScreenVirtualButtons.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
import sys
from kivy.clock import Clock
from kivy.core.image import Image
from kivy.graphics.texture import Texture
import numpy as np
from kivy.cache import Cache
try:
import cv2
except:
print("E no cv2!")
#sys.exit(-43)
class ScreenVirtualButtons:
def __init__(self,gui):
self.gui = gui
self.running = False
self.cam = cv2.VideoCapture(0)
self.tex = None
self.objs = {
'lighter': cv2.imread("ocv/lighter.png")#,
#'sharpyEnd': cv2.imread('ocv/sharpyEnd.png'),
#'pinch' : cv2.imread("ocv/pinch.png")
}
def on_displayNow(self):
if self.running == False:
self.running = True
self.iter(0)
def on_noMoreDisplayd(self):
self.running = False
def iter(self,a):
#print("svb")
r,img = self.cam.read()
img = cv2.flip(img,1)
"""
if self.tex == None:
s = img.shape
self.tex = Texture.create(size=(s[0],s[1]), colorfmt='rgb')
self.tex.blit_buffer(img, colorfmt='rgb',bufferfmt='ubyte')
"""
for k in self.objs.keys():
res = cv2.matchTemplate(img, self.objs[k], cv2.TM_CCOEFF_NORMED)
thresh = 0.4
loc = np.where( res >= thresh )
w,h,_ = self.objs[k].shape
for pt in zip(*loc[::-1]):
img = cv2.putText(img, k, pt, cv2.FONT_HERSHEY_SIMPLEX,1,255,2,cv2.LINE_AA )
img = cv2.rectangle(img, pt, (pt[0] + w, pt[1] + h), (0,0,255), 2)
break
cv2.imwrite('/tmp/svb.png',img)
Cache.remove('kv.image')
Cache.remove('kv.texture')
self.gui.rl.ids.iVirButCam.texture = Image('/tmp/svb.png').texture
if self.running:
Clock.schedule_once(self.iter,0.1)