Ejemplo n.º 1
0
class Handwave:
    def __init__(self, display):
        self.output_port = display
        self.image_hand = [
            imread('behaviours/images/hand_wave0.jpg', CV_LOAD_IMAGE_COLOR),
            imread('behaviours/images/hand_wave1.jpg', CV_LOAD_IMAGE_COLOR),
            imread('behaviours/images/hand_wave2.jpg', CV_LOAD_IMAGE_COLOR),
            imread('behaviours/images/hand_wave1.jpg', CV_LOAD_IMAGE_COLOR)
        ]
        self.image_black = imread('behaviours/images/black_background.jpg',
                                  CV_LOAD_IMAGE_COLOR)
        self.bell = Sound('behaviours/sounds/airplane_bell.wav')

    def push(self, data):
        return True

    def condition(self):
        """Return default True condition"""
        return True

    def show(self):
        """Display handwaving animation"""
        self.bell.play()
        for j in range(0, 3):
            for i in range(0, 4):
                imshow(self.output_port, self.image_hand[i])
                waitKey(200)
        imshow(self.output_port, self.image_black)
        waitKey(20)
Ejemplo n.º 2
0
class Coffee:
    FIKA_START_HOUR = 14
    FIKA_END_HOUR = 15
    FIKA_START_MIN = 30
    FIKA_END_MIN = 30

    def __init__(self, display):
        self.output_port = display
        self.image_coffee = [imread('behaviours/images/coffee_cup0.jpg',CV_LOAD_IMAGE_COLOR),imread('behaviours/images/coffee_cup1.jpg',CV_LOAD_IMAGE_COLOR),imread('behaviours/images/coffee_cup2.jpg',CV_LOAD_IMAGE_COLOR)]
        self.image_black = imread('behaviours/images/black_background.jpg',CV_LOAD_IMAGE_COLOR)
	self.bell = Sound('behaviours/sounds/airplane_bell.wav')

    def push(self,data):
        return True

    def condition(self):
        """Check if it is fika time!"""
        current_time = datetime.datetime.now()
        return current_time.hour*60+current_time.minute > 60*self.FIKA_START_HOUR+self.FIKA_START_MIN and current_time.hour*60+current_time.minute < 60*self.FIKA_END_HOUR+self.FIKA_END_MIN

    def show(self):
        """Display handwaving animation"""
	self.bell.play()
        for j in range(0,3):
            for i in (1,0,1,2):
                imshow(self.output_port,self.image_coffee[i])
                waitKey(200)
        imshow(self.output_port,self.image_black)
        waitKey(20)
Ejemplo n.º 3
0
class Cow:
    COW_PROBABILITY = 0.05

    def __init__(self, display):
        self.output_port = display
        self.image_cow = imread('behaviours/images/cow.jpg',
                                CV_LOAD_IMAGE_COLOR)
        self.image_black = imread('behaviours/images/black_background.jpg',
                                  CV_LOAD_IMAGE_COLOR)
        self.moo = Sound('behaviours/sounds/cow_moo.wav')
        self.nextiscow = False

    def push(self, data):
        self.nextiscow = uniform() < self.COW_PROBABILITY  # Update cow event
        return True

    def condition(self):
        return self.nextiscow  # Do we have a cow pending?

    def show(self):  # Show the cow!
        self.moo.play()
        imshow(self.output_port, self.image_cow)
        waitKey(5000)
        imshow(self.output_port, self.image_black)
        waitKey(20)
        self.nextiscow = False  # Clear the pending cow...
Ejemplo n.º 4
0
class Coffee:
    FIKA_START_HOUR = 14
    FIKA_END_HOUR = 15
    FIKA_START_MIN = 30
    FIKA_END_MIN = 30

    def __init__(self, display):
        self.output_port = display
        self.image_coffee = [
            imread('behaviours/images/coffee_cup0.jpg', CV_LOAD_IMAGE_COLOR),
            imread('behaviours/images/coffee_cup1.jpg', CV_LOAD_IMAGE_COLOR),
            imread('behaviours/images/coffee_cup2.jpg', CV_LOAD_IMAGE_COLOR)
        ]
        self.image_black = imread('behaviours/images/black_background.jpg',
                                  CV_LOAD_IMAGE_COLOR)
        self.bell = Sound('behaviours/sounds/airplane_bell.wav')

    def push(self, data):
        return True

    def condition(self):
        """Check if it is fika time!"""
        current_time = datetime.datetime.now()
        return current_time.hour * 60 + current_time.minute > 60 * self.FIKA_START_HOUR + self.FIKA_START_MIN and current_time.hour * 60 + current_time.minute < 60 * self.FIKA_END_HOUR + self.FIKA_END_MIN

    def show(self):
        """Display handwaving animation"""
        self.bell.play()
        for j in range(0, 3):
            for i in (1, 0, 1, 2):
                imshow(self.output_port, self.image_coffee[i])
                waitKey(200)
        imshow(self.output_port, self.image_black)
        waitKey(20)
Ejemplo n.º 5
0
 def __init__(self, display):
     self.output_port = display
     self.image_cow = imread('behaviours/images/cow.jpg',
                             CV_LOAD_IMAGE_COLOR)
     self.image_black = imread('behaviours/images/black_background.jpg',
                               CV_LOAD_IMAGE_COLOR)
     self.moo = Sound('behaviours/sounds/cow_moo.wav')
     self.nextiscow = False
Ejemplo n.º 6
0
 def __init__(self, display):
     self.output_port = display
     self.image_black = imread('behaviours/images/black_background.jpg',
                               CV_LOAD_IMAGE_COLOR)
     self.fanfare = Sound(
         'behaviours/sounds/formula1.wav')  # ADD SOME COOL SOUND
     self.today = datetime.datetime.now().day
     self.max_speed_today = 0
Ejemplo n.º 7
0
 def __init__(self, display):
     self.output_port = display
     self.image_coffee = [
         imread('behaviours/images/coffee_cup0.jpg', CV_LOAD_IMAGE_COLOR),
         imread('behaviours/images/coffee_cup1.jpg', CV_LOAD_IMAGE_COLOR),
         imread('behaviours/images/coffee_cup2.jpg', CV_LOAD_IMAGE_COLOR)
     ]
     self.image_black = imread('behaviours/images/black_background.jpg',
                               CV_LOAD_IMAGE_COLOR)
     self.bell = Sound('behaviours/sounds/airplane_bell.wav')
Ejemplo n.º 8
0
class Fastest:

    SPEED_CONVERSION = 0.015517241

    def __init__(self, display):
        self.output_port = display
        self.image_black = imread('behaviours/images/black_background.jpg',
                                  CV_LOAD_IMAGE_COLOR)
        self.fanfare = Sound(
            'behaviours/sounds/formula1.wav')  # ADD SOME COOL SOUND
        self.today = datetime.datetime.now().day
        self.max_speed_today = 0

    def push(self, data):
        self.speed = data[0]
        self.speed = self.SPEED_CONVERSION * self.speed  # Convert from px/sec to km/h
        return True

    def condition(self):
        # If the current date is different from the one in the last detection reset the maxspeed
        # and the date
        if not datetime.datetime.now().day == self.today:
            self.max_speed_today = 0
            self.today = datetime.datetime.now().day
        # If the speed is highest today
        if self.speed > self.max_speed_today:
            self.max_speed_today = self.speed
            return True
        else:
            return False

    def show(self):
        # Image with no text
        self.image_text = self.image_black.copy()
        self.fanfare.play()
        self.textcolor = (0, 255, 255)  # YELLOW
        putText(self.image_text, 'You are the', (70, 120), FONT_HERSHEY_PLAIN,
                8, self.textcolor, 10)
        putText(self.image_text, ' Fastest', (70, 300), FONT_HERSHEY_PLAIN, 10,
                self.textcolor, 14)
        putText(self.image_text, '  today', (70, 450), FONT_HERSHEY_PLAIN, 10,
                self.textcolor, 10)
        putText(self.image_text, "{:.1f}".format(self.speed) + ' km/h!',
                (50, 600), FONT_HERSHEY_PLAIN, 10, self.textcolor, 10)
        for i in range(5):
            imshow(self.output_port, self.image_text)
            waitKey(600)
            imshow(self.output_port, self.image_black)
            waitKey(300)
Ejemplo n.º 9
0
class Speed:

    GREEN_SPEED = 5
    SPEED_CONVERSION = 0.014794541

    def __init__(self,display):
        self.output_port = display
        self.image_black = imread('behaviours/images/black_background.jpg',CV_LOAD_IMAGE_COLOR)
        self.fail = Sound('behaviours/sounds/fail.wav')
        self.tada = Sound('behaviours/sounds/tada.wav')


    def push(self,data):
        self.speed = data[0]
	self.speed = self.SPEED_CONVERSION*self.speed # Convert from px/sec to km/h
        return True

    def condition(self):
        return True

    def show(self):
        # Image with no text
        self.image_text = self.image_black.copy()

        if abs(self.speed -  self.GREEN_SPEED) < 0.05: # If we are going at the right speed
            self.tada.play()
            self.textcolor = (0, 255, 0) # GREEN
            putText(self.image_text,'You walk:',(50,200),FONT_HERSHEY_PLAIN,10,self.textcolor,10)
            putText(self.image_text,'Exactly',(50,400),FONT_HERSHEY_PLAIN,10,self.textcolor,10)
            putText(self.image_text,"{:.1f}".format(self.GREEN_SPEED)+' km/h',(50,600),FONT_HERSHEY_PLAIN,10,self.textcolor,10)
            for i in range(5):
                imshow(self.output_port, self.image_text)
                waitKey(600)
                imshow(self.output_port, self.image_black)
                waitKey(300)
        else: # ...do something else
            if self.speed > self.GREEN_SPEED: # if too fast...
                self.textcolor = (0,0,255) # RED
                putText(self.image_text,'Walk slower!',(50,600),FONT_HERSHEY_PLAIN,9,self.textcolor,10)
            if self.speed < self.GREEN_SPEED: # if too fast...
                self.textcolor = (255,0,0) # BLUE
                putText(self.image_text,'Walk faster!',(50,600),FONT_HERSHEY_PLAIN,9,self.textcolor,10)
            self.fail.play()
            putText(self.image_text,'You walk:',(50,200),FONT_HERSHEY_PLAIN,10,self.textcolor,10)
            putText(self.image_text,"{:.1f}".format(self.speed)+' km/h',(50,400),FONT_HERSHEY_PLAIN,10,self.textcolor,10)
            imshow(self.output_port,self.image_text)
            waitKey(5000)
            imshow(self.output_port,self.image_black)
Ejemplo n.º 10
0
class Fastest:

    SPEED_CONVERSION = 0.015517241

    def __init__(self,display):
        self.output_port = display
        self.image_black = imread('behaviours/images/black_background.jpg',CV_LOAD_IMAGE_COLOR)
        self.fanfare = Sound('behaviours/sounds/formula1.wav') # ADD SOME COOL SOUND
        self.today = datetime.datetime.now().day
        self.max_speed_today = 0

    def push(self,data):
        self.speed = data[0]
        self.speed = self.SPEED_CONVERSION*self.speed # Convert from px/sec to km/h
        return True

    def condition(self):
        # If the current date is different from the one in the last detection reset the maxspeed
        # and the date
        if not datetime.datetime.now().day == self.today:
            self. max_speed_today = 0
            self.today = datetime.datetime.now().day
        # If the speed is highest today
        if self.speed > self.max_speed_today:
            self.max_speed_today = self.speed
            return True
        else:
            return False

    def show(self):
        # Image with no text
        self.image_text = self.image_black.copy()
        self.fanfare.play()
        self.textcolor = (0 , 255, 255) # YELLOW
        putText(self.image_text,'You are the',(70,120),FONT_HERSHEY_PLAIN,8,self.textcolor,10)
        putText(self.image_text,' Fastest',(70,300),FONT_HERSHEY_PLAIN,10,self.textcolor,14)
        putText(self.image_text,'  today',(70,450),FONT_HERSHEY_PLAIN,10,self.textcolor,10)
        putText(self.image_text,"{:.1f}".format(self.speed)+' km/h!',(50,600),FONT_HERSHEY_PLAIN,10,self.textcolor,10)
        for i in range(5):
            imshow(self.output_port, self.image_text)
            waitKey(600)
            imshow(self.output_port, self.image_black)
            waitKey(300)
Ejemplo n.º 11
0
class Handwave:
    def __init__(self, display):
        self.output_port = display
        self.image_hand= [imread('behaviours/images/hand_wave0.jpg',CV_LOAD_IMAGE_COLOR),imread('behaviours/images/hand_wave1.jpg',CV_LOAD_IMAGE_COLOR),imread('behaviours/images/hand_wave2.jpg',CV_LOAD_IMAGE_COLOR),imread('behaviours/images/hand_wave1.jpg',CV_LOAD_IMAGE_COLOR)]
        self.image_black = imread('behaviours/images/black_background.jpg',CV_LOAD_IMAGE_COLOR)
	self.bell = Sound('behaviours/sounds/airplane_bell.wav')

    def push(self,data):
        return True

    def condition(self):
        """Return default True condition"""
        return True

    def show(self):
        """Display handwaving animation"""
	self.bell.play()
        for j in range(0,3):
            for i in range(0,4):
                imshow(self.output_port,self.image_hand[i])
                waitKey(200)
        imshow(self.output_port,self.image_black)
        waitKey(20)
Ejemplo n.º 12
0
class Cow:
    COW_PROBABILITY = 0.05

    def __init__(self, display):
        self.output_port = display
        self.image_cow = imread('behaviours/images/cow.jpg',CV_LOAD_IMAGE_COLOR)
        self.image_black = imread('behaviours/images/black_background.jpg',CV_LOAD_IMAGE_COLOR)
        self.moo = Sound('behaviours/sounds/cow_moo.wav')
        self.nextiscow = False

    def push(self,data):
        self.nextiscow = uniform() < self.COW_PROBABILITY # Update cow event
        return True

    def condition(self):
        return self.nextiscow # Do we have a cow pending?

    def show(self): # Show the cow!
        self.moo.play()
        imshow(self.output_port,self.image_cow)
        waitKey(5000)
        imshow(self.output_port,self.image_black)
        waitKey(20)
        self.nextiscow = False # Clear the pending cow...
Ejemplo n.º 13
0
    def __init__(self, display):
        self.output_port = display
        self.image_coffee = [imread('behaviours/images/coffee_cup0.jpg',CV_LOAD_IMAGE_COLOR),imread('behaviours/images/coffee_cup1.jpg',CV_LOAD_IMAGE_COLOR),imread('behaviours/images/coffee_cup2.jpg',CV_LOAD_IMAGE_COLOR)]
        self.image_black = imread('behaviours/images/black_background.jpg',CV_LOAD_IMAGE_COLOR)
	self.bell = Sound('behaviours/sounds/airplane_bell.wav')
Ejemplo n.º 14
0
 def __init__(self,display):
     self.output_port = display
     self.image_black = imread('behaviours/images/black_background.jpg',CV_LOAD_IMAGE_COLOR)
     self.fail = Sound('behaviours/sounds/fail.wav')
     self.tada = Sound('behaviours/sounds/tada.wav')
Ejemplo n.º 15
0
 def __init__(self,display):
     self.output_port = display
     self.image_black = imread('behaviours/images/black_background.jpg',CV_LOAD_IMAGE_COLOR)
     self.fanfare = Sound('behaviours/sounds/formula1.wav') # ADD SOME COOL SOUND
     self.today = datetime.datetime.now().day
     self.max_speed_today = 0
Ejemplo n.º 16
0
 def __init__(self, display):
     self.output_port = display
     self.image_cow = imread('behaviours/images/cow.jpg',CV_LOAD_IMAGE_COLOR)
     self.image_black = imread('behaviours/images/black_background.jpg',CV_LOAD_IMAGE_COLOR)
     self.moo = Sound('behaviours/sounds/cow_moo.wav')
     self.nextiscow = False