-
Notifications
You must be signed in to change notification settings - Fork 0
/
alarmyolo.py
80 lines (70 loc) · 1.92 KB
/
alarmyolo.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
from picamera import PiCamera
from subprocess import Popen, PIPE
import threading
from time import sleep
import os, fcntl
import cv2
#camera = PiCamera()
#iframe = 0
def detect():
# os.system("sudo ./hub-ctrl -h 1 -P 2 -p 1")
# camera = pi
camera = PiCamera()
#Yolo v3 is a full convolutional model. It does not care the size of input image, as long as h and w are multiplication of 32
#camera.resolution = (160,160)
#camera.resolution = (416, 416)
#camera.resolution = (544, 544)
camera.resolution = (608, 608)
#camera.resolution = (608, 288)
#camera.capture('frame.jpg')
#sleep(0.1)
#spawn darknet process
yolo_proc = Popen(["./darknet",
"detector",
"test",
"obj.data",
"./yolov3-custom.cfg",
"./yolov3-custom.weights",
"-thresh","0.1"],
stdin = PIPE, stdout = PIPE)
fcntl.fcntl(yolo_proc.stdout.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)
cnt = 0
print("cnt : " +str(cnt))
tf = 0
print("tf : "+ str(tf))
while True:
try:
stdout = yolo_proc.stdout.read()
if 'Enter Image Path' in stdout:
# try:
# im = cv2.imread('predictions.png')
## print(im.shape)
# cv2.imshow('record',im)
# key = cv2.waitKey(5)
# except Exception:
# pass
camera.capture('frame.jpg')
yolo_proc.stdin.write('frame.jpg\n')
if len(stdout.strip())>0:
print('start get %s end' % stdout)
if(stdout.find("sleep") != -1):
print("find sleeping person")
tf += 1
print(tf)
if tf == 1 :
print("wake up")
yolo_proc.kill()
camera.close()
# os.system("sudo ./hub-ctrl -h 1 -P 2 -p 0")
return True
cnt += 1
print("count : " + str(cnt))
if cnt == 2:
print("False")
camera.close()
yolo_proc.kill()
# os.system("sudo ./hub-ctrl -h 1 -P 2 -p 0")
return False
except Exception:
pass
#print(detect())