| 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
|
from pyrobot.brain.behaviors import *
from pyrobot.brain.behaviors.core import *
from time import *
from phissioncamera import *
camera = phissioncamera()
class MotionCatch(State):
def onActivate(self):
print "Activating MotionCatch State"
self.motion_thresh = 1000
camera.motion_Filter()
sleep(1)
def update(self):
max_blob = camera.getMaxBlob()
if(max_blob.mass > self.motion_thresh):
camera.SpotColorTrackHSV_Filter(max_blob.cx, max_blob.cy, 15, (12, 60, 200) )
self.goto('ColorTrack')
class ColorTrack(State):
def onActivate(self):
print "Activating ColorTrack State"
sleep(1)
self.track_thresh = 1000
def update(self):
max_blob = camera.getMaxBlob()
print "-------------------"
print "mass =", max_blob.mass
print "(x,y) = ", max_blob.cx, max_blob.cy
if(max_blob.mass < self.track_thresh):
self.goto('MotionCatch')
class state1(State):
def update(self):
self.goto('MotionCatch')
def INIT(engine):
brain = FSMBrain(engine)
brain.add(state1(1))
brain.add(MotionCatch())
brain.add(ColorTrack())
brain.camera = camera
camera.setup(1,320,240)
return brain |