-
Notifications
You must be signed in to change notification settings - Fork 1
/
GiaoRobot.py
77 lines (65 loc) · 2.61 KB
/
GiaoRobot.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
import cv2
import time
import config
from logger import Logger
from push import Push
from storage import Storage
from camera import Camera
from utils import draw_bboxes
log = Logger.getLogger("Giao")
def main():
# open camera
cap = cv2.VideoCapture(0)
last_send_time = 0
camera = Camera(config.TinyFaceModelPath, config.TinyFaceModelDevice)
push = Push(config.dingTalkWebhookAccessToken)
storage = Storage(config.SinaSCSAccessKey, config.SinaSCSSecretKey, config.SinaSCSBucketName,
config.SinaSCSBucketUrl)
regionX = config.MonitorRegion['x']
regionY = config.MonitorRegion['y']
regionW = config.MonitorRegion['w']
regionH = config.MonitorRegion['h']
while (cap.isOpened()):
try:
ret, img = cap.read()
if ret == True:
imgRegion = img[regionY:regionY + regionH, regionX:regionX + regionW]
diff = camera.detectDiff(imgRegion)
if diff < config.MonitorDiffThreshold:
time.sleep(0.2)
continue
faceNum, predType, predName = camera.detectFaces(imgRegion)
log.info("faceNum: %d", faceNum)
if faceNum > 0:
if predType[1]:
typeStr = '确定'
else:
typeStr = '可能'
if predType[0] == 0:
typeStr += '进入'
elif predType[0] == 1:
typeStr += '离开'
else:
typeStr += '站起来了'
if predName[1]:
nameStr = '确定是'
else:
nameStr = '可能是'
nameStr += config.PersonNames[predName[0]]
content = nameStr + ',' + typeStr
log.info('push content %s', content)
if faceNum > 0 and (time.time() - last_send_time) > 30:
last_send_time = time.time()
saveName = str(time.strftime('images/%Y%m%d_%H_%M_%S.png'))
cv2.imwrite(saveName, img)
saveName = str(time.strftime('images/%Y%m%d_%H_%M_%S.jpg'))
cv2.imwrite(saveName, img)
url = storage.saveImage(saveName)
log.info("send giao! %s" % url)
push.sendImage(config.PushTitle, content, url)
except Exception as e:
log.error("error: %s", e)
# time.sleep(0.5)
cap.release()
if __name__ == '__main__':
main()