-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
90 lines (77 loc) · 2.92 KB
/
main.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
89
#! /usr/bin/env python
###############################################################################
##
## main.py -- part of the bypasser program
##
## Copyright (c) 2014 Riccardo Sven Risuleo
##
## This software may be modified and distributed under the terms
## of the MIT license. See the LICENSE file for details.
##
###############################################################################
#from utilities.nonthreading_cameracontroller import CameraController
from utilities.nonthreading_cameracontroller import CameraController
from utilities.motiondetector import MotionDetector
from utilities.datalogger import Datalogger
from utilities.imagesave import Imagesave
from utilities.graphsave import Graphsave
from behaviours.handwave import Handwave
from behaviours.cow import Cow
from behaviours.coffee import Coffee
from behaviours.speed import Speed
from behaviours.fastest import Fastest
import sys
from cv2 import namedWindow, waitKey, imshow
from time import sleep
# Initialize a new motion controller object
camera = CameraController()
detector = MotionDetector(camera)
# Start main output display
namedWindow('Display')
waitKey(20)
namedWindow('Debug')
# Start the dataloggers
log = Datalogger('detection_log.log')
imageprinter = Imagesave('captured_images')
plotprinter = Graphsave('captured_plots')
# Initialize output behaviours, the argument is the viewport they are going to use to display the output
handwaves = Handwave('Display')
cow = Cow('Display')
speed = Speed('Display')
coffetime = Coffee('Display')
fastest = Fastest('Display')
# List the effects, in order of precedence
effect_list = [cow, fastest, coffetime, speed, handwaves]
# Start camera controller thread
# camera.start()
key = -1
#while key != 27: # 1048603
while key == -1: # 1048603
# Update the detector
camera.update() # For nonthreading camera
sys.stdout.write('%s fps\r'%camera.framerate())
sys.stdout.flush()
difference_image = camera.fetch(camera.DIFFERENCE)
camera_frame = camera.fetch(camera.IMAGE)
detector.update(camera_frame,difference_image)
detector_data = detector.data()
detector_dump = detector.dump()
abs_difference_image = camera.fetch(camera.ABS_DIFFERENCE)
imshow('Debug',abs_difference_image)
# If we have a detector...
if detector.detection():
# ...cycle through the effects...
for effect in effect_list:
effect.push(detector_data)
# ...checking if the conditions for one is true...
if effect.condition():
imageprinter.save(camera_frame)
plotprinter.save(detector_dump[0],detector_dump[1],detector_data[0],detector_data[1])
log.update(detector_data,cow.condition())
# ...showing that effect...
effect.show()
break #...and that's it for now!
# Update viewport... maybe not needed...
key = waitKey(10)
# Kill camera thread
camera.deactivate()