예제 #1
0
def main(args):
    train_x, train_y, test = make_datasets(path, args.train_size,
                                           args.test_size)

    eyes = Eyes()
    model = eyes.build_graph()
    model.summary()
    plot_model(model, to_file='model.png')

    tensorboard = TensorBoard(log_dir=args.log_path, histogram_freq=10)
    earlystop = EarlyStopping(monitor='val_loss',
                              min_delta=0,
                              patience=0,
                              verbose=1,
                              mode='auto')
    history = model.fit(x=train_x,
                        y=train_y,
                        epochs=args.epochs,
                        verbose=1,
                        batch_size=args.batch_size,
                        validation_split=0.5,
                        callbacks=[earlystop])
    model.save_weights(args.save_weights)

    result = model.predict(test[:10])
    imshow(result)
예제 #2
0
파일: robot.py 프로젝트: rcschen/chungtao
class Chuntao(Robot):
      def __init__(self, kickstart):
          self.eyes = Eyes(kickstart)
          self.brain = Brain(kickstart)
          self.feet = WheelFeet(kickstart)
          super(Chuntao, self).__init__()

      def _set_brain(self):
          self._senses.append(self.brain)

      def _set_eyes(self):
          frameQueue = QueueFactory().getQueue('simple')
          self._senses.append(self.eyes)
          self.eyes.setFrameQueue(frameQueue)
          self.brain.setQueue('frameQueue', frameQueue)

      def _set_feet(self):
          feetCommandQueue = QueueFactory().getQueue('simple')
          self._senses.append(self.feet)
          self.feet.setCommandQueue(feetCommandQueue)
          self.brain.setQueue('feetCommandQueue', feetCommandQueue)

      def _set_senses(self):
          self._set_eyes()
          print "eye"
          self._set_feet()
          print "feet"
          self._set_brain()
          print "brain"

      def manualFeetControl(self, *par):
          self.brain.feetControl(*par)
예제 #3
0
파일: eyes3.py 프로젝트: arcosaka/arcosaka
def eyes_py(id):
    global polePosX, polePosY, dispar, sadws

    # 初期化宣言 : このソフトウェアは"eyes_py_node"という名前
    rospy.init_node('eyes_py_node', anonymous=True)

    # インスタンスの作成 
    eyes = Eyes(id)

    # 処理周期の設定
    r = rospy.Rate(PUB_RATE)

    print("[eyes3] start")
    # ctl + Cで終了しない限りwhileループで処理し続ける
    while not rospy.is_shutdown():

        #==================================================
        # Loop
        ret0, imgL = RP3_Cap_L.read()
        ret1, imgR = RP3_Cap_R.read()

        if dispMode == 1:
            cv2.imshow( "Left  Camera", imgL )
            cv2.imshow( "Right Camera", imgR )

            #-- Create DiparityMap --
            disparity = GetDisparityMap()

            #-- Cal Pole Distance --
            capL_target = GetBlueDetect( imgL )
            Lx, Ly, Lw, Lh = cv2.boundingRect( capL_target )

            capR_target = GetBlueDetect( imgR )
            Rx, Ry, Rw, Rh = cv2.boundingRect( capR_target )

            # Xは左右中心の更に中心
            Lpos = Lx + (Lw / 2)
            Rpos = Rx + (Rw / 2)
            polePosX = (Lpos + Rpos) / 2
            # Yは片側基準でOK
            polePosY = Ly + (Lh / 2)

            # from disparity to dist
            # Z = f x T / um / disparity
            poleDist = 6.6 * 62 / 0.003 / disparity[polePosY][polePosX]
            print polePosX, polePosY, poleDist

            if dispMode == 1:
                cv2.rectangle( imgL, (Lx, Ly), (Lx + Lw, Ly + Lh), (0, 0, 255), 1 )
                cv2.imshow( "Left Pole", imgL )
                cv2.rectangle( imgR, (Rx, Ry), (Rx + Rw, Ry + Rh), (0, 0, 255), 1 )
                cv2.imshow( "Right Pole", imgR )

        #==================================================
        # メイン処理
        eyes.main()

        # Sleep処理
        r.sleep()
예제 #4
0
 def __init__(self, body, image):
     self.body = body
     self.hindbrain = Hindbrain()
     view_distance = image.get('behaviour', {}).get('target range', 200)
     self.eyes = Eyes(view_distance=view_distance)
     self.self_image = image
     self.parse_behaviour(image.get('behaviour', {}))
     self.wander_value = 0
예제 #5
0
 def __init__(self, maze, pacman, game_controller):
     self.CHAR_WIDTH = 100
     self.CHAR_HEIGHT = 100
     self.maze = maze
     self.pacman = pacman
     self.gc = game_controller
     self.x = maze.WIDTH/2
     self.y = maze.TOP_HORIZ
     self.velocity = 2
     self.x_add = self.velocity
     self.y_add = 0
     self.eyes = Eyes()
     self.looking = (0, 0)
     self.WIN_PROXIMITY = 80
     self.WALL_TOLERANCE = 2
    def set_objects(self):
        Builder.load_file("main.kv")
        self.size = (Window.width, Window.height)
        self.eyes = Eyes(box=[
            self.game_area.x, self.game_area.y +
            65, self.game_area.width, self.game_area.height - 175
        ])

        self.nose = Nose(box=[
            self.game_area.x, self.game_area.y +
            65, self.game_area.width, self.game_area.height - 175
        ])

        self.mouth = Mouth(box=[
            self.game_area.x, self.game_area.y +
            65, self.game_area.width, self.game_area.height - 175
        ])

        self.game_area.add_widget(self.eyes, index=1)
        self.eyes.active = True

        self.game_area.add_widget(self.mouth, index=1)
        self.mouth.active = True
        #        self.auto_bring_to_front(self.mouth) # nekoja vakva kombinacija da se napravi :)

        self.game_area.add_widget(self.nose, index=1)
        self.nose.active = True
예제 #7
0
    def __init__(self, port=DEFAULT_PORT, logdir='/var/log/xm'):
        """Creates a new istance of the body. By default it's composed by
        a thread-safe version of `Legs`, `Mouth` and `Eyes`.

        Args:
            port (str): serial port `Legs` will connect to.
            logdir (str): path where to store logs.
        """
        self.safe_legs = LockAdapter(Legs(port))

        eye_log = '{}-eyes.log'.format(str(datetime.date.today()))
        self.safe_mouth = Mouth()
        self.safe_eye = Eyes(log=open(os.path.join(logdir, eye_log), 'w'))

        self.circuits = {}

        self.add_circuit('forward',
                         target=self.safe_legs.forward,
                         pre=[move_synapse])
        self.add_circuit('backward',
                         target=self.safe_legs.backward,
                         pre=[move_synapse])
        self.add_circuit('left',
                         target=self.safe_legs.left,
                         pre=[move_synapse])
        self.add_circuit('right',
                         target=self.safe_legs.right,
                         pre=[move_synapse])
        self.add_circuit('stop', target=self.safe_legs.stop)
        self.add_circuit('set_speed',
                         target=self.safe_legs.set_speed,
                         pre=[speedvalue_synapse])
        self.add_circuit('set_movetime',
                         target=self.safe_legs.set_movetime,
                         pre=[movetime_synapse])

        self.add_circuit('say', target=self.safe_mouth.say, pre=[say_synapse])
        self.add_circuit('shutup', target=self.safe_mouth.shutup)

        self.add_circuit('open_eyes', target=self.safe_eye.open)
        self.add_circuit('close_eyes', target=self.safe_eye.close)
예제 #8
0
파일: pinky.py 프로젝트: yiyu-t/Pacman
class Pinky(GameCharacter):
    def __init__(self, maze, pacman, game_controller):
        self.CHAR_WIDTH = 100
        self.CHAR_HEIGHT = 100
        self.maze = maze
        self.pacman = pacman
        self.gc = game_controller
        self.x = maze.WIDTH / 2
        self.y = maze.TOP_HORIZ
        self.velocity = 2
        self.x_add = self.velocity
        self.y_add = 0
        self.eyes = Eyes()
        self.looking = (0, 0)
        self.WIN_PROXIMITY = 80
        self.WALL_TOLERANCE = 2

    def draw_self(self, x, y):
        """Draw Pinky to the screen"""
        noStroke()
        fill(1.0, 0.5, 0.6)
        ellipse(x, y, 100, 100)
        bottom_half = createShape()
        bottom_half.beginShape()
        bottom_half.vertex(x, y)
        bottom_half.vertex(x + 100, y)
        bottom_half.vertex(x + 100, y + 50)
        bottom_half.vertex(x + 50, y + 25)
        bottom_half.vertex(x, y + 50)
        bottom_half.endShape()
        shape(bottom_half, -50, 0)

        self.eyes.display(x, y - 15, self.looking)

    def update(self):
        """Carry out necessary updates for each frame before
        drawing to screen"""
        # Check if Pinky is at an intersection
        on_vert = ((abs(self.x - self.maze.LEFT_VERT) < self.WALL_TOLERANCE) or
                   (abs(self.x - self.maze.RIGHT_VERT) < self.WALL_TOLERANCE))
        on_horz = (
            (abs(self.y - self.maze.TOP_HORIZ) < self.WALL_TOLERANCE)
            or (abs(self.y - self.maze.BOTTOM_HORIZ) < self.WALL_TOLERANCE))

        # Check whether Pinky is up or down/left or right of Pacman
        up_down_part = self.pacman.y - self.y
        left_right_part = self.pacman.x - self.x

        # Update Pinky's eyes to look at Pacman
        self.update_eyes(up_down_part, left_right_part)

        # If Pinky gets close to Pacman, tell the GameController
        # that Pinky wins
        if (abs(up_down_part) < self.WIN_PROXIMITY
                and abs(left_right_part) < self.WIN_PROXIMITY):
            self.gc.pinky_wins = True

        # Make Pinky chase Pacman
        if on_vert and on_horz:
            if abs(up_down_part) > abs(left_right_part):
                self.y_add = self.velocity * (up_down_part / abs(up_down_part))
                self.x_add = 0
            elif abs(up_down_part) < abs(left_right_part):
                self.x_add = self.velocity * \
                    (left_right_part/abs(left_right_part))
                self.y_add = 0

        # If the player wins, stop Pinky moving
        if self.gc.player_wins:
            self.x_add = 0
            self.y_add = 0

        # Move Pinky
        self.x = self.x + self.x_add
        self.y = self.y + self.y_add

    def update_eyes(self, up_down_part, left_right_part):
        """Set self.looking value based on position of Pinky w/r/t Pacman"""
        if up_down_part and abs(up_down_part) > 5:
            y = up_down_part / abs(up_down_part)
        else:
            y = 0
        if left_right_part and abs(left_right_part) > 5:
            x = left_right_part / abs(left_right_part)
        else:
            x = 0
        self.looking = (x, y)
예제 #9
0
def test_constructor():
    """Test Eyes constructor"""
    es = Eyes()
    assert es.left_eye.direction == es.right_eye.direction == (0, 0)
예제 #10
0
class Brain(object):
    def __init__(self, body, image):
        self.body = body
        self.hindbrain = Hindbrain()
        view_distance = image.get('behaviour', {}).get('target range', 200)
        self.eyes = Eyes(view_distance=view_distance)
        self.self_image = image
        self.parse_behaviour(image.get('behaviour', {}))
        self.wander_value = 0

    def update(self, list_of_game_objects):
        self.eyes.update(list_of_game_objects)
        self.memory.update()
        self.action_getter.update()
        self.goal_getter.update()
        self.action = self.action_getter.action

    def parse_behaviour(self, behaviour_dict):
        if behaviour_dict.get('goap', False):
            self.action_getter = ActionPlanner(self.self_image, self.eyes,
                                               self.body)
        else:
            self.action_getter = ActionGetter(self.self_image, self.eyes,
                                              self.body)
        if behaviour_dict.get('pathfind', False):
            self.memory = Memory(self.body, self.eyes)
            self.goal_getter = PathFindingGoalGetter(self.body, self.eyes,
                                                     self.memory)
        elif behaviour_dict.get('fast pathfind', False):
            self.memory = DumbMemory(self.body, self.eyes)
            self.goal_getter = FastPathFindingGoalGetter(
                self.body, self.eyes, self.memory)
        else:
            self.memory = DumbMemory(self.body, self.eyes)
            self.goal_getter = GoalGetter(self.body, self.eyes)
        self.target = behaviour_dict.get('target')
        self.target_range = behaviour_dict.get('target range')

    def seek(self, target_position, collision):
        vector_to_target = self.hindbrain.calculate_vector_to_target(
            self.body.coords, self.body.velocity, target_position)
        avoid_vector = self.hindbrain.avoid(self.body.coords,
                                            vector_to_target,
                                            collision,
                                            target_position=target_position)
        arrive_factor = self.hindbrain.arrive_factor(self.body.coords,
                                                     self.body.velocity,
                                                     target_position)
        return normalise_vector(vector_to_target +
                                avoid_vector) * arrive_factor

    def flee(self, scary_thing, collision):
        vector_to_target = self.hindbrain.calculate_vector_to_target(
            self.body.coords, self.body.velocity, scary_thing)
        vector = -vector_to_target
        avoid_vector = self.hindbrain.avoid(self.body.coords,
                                            vector,
                                            collision,
                                            target_position=None)
        return normalise_vector(vector + avoid_vector)

    def wander(self, goal, collision):
        if collision is not None:
            vector = self.hindbrain.calculate_vector_to_target(
                self.body.coords, self.body.velocity,
                collision['intersection'])
            return -vector
        change_chance = 0.07
        turn_force = 0.7
        if random.uniform(0, 1) < change_chance:
            self.wander_value = random.choice([-2, -1, 0, 0, 1, 2
                                               ]) * turn_force
        wander_force = (normalise_vector(
            perpendicular_vector(self.body.velocity))) * self.wander_value
        vector = normalise_vector(self.body.velocity + wander_force)
        if vector.sum() == 0:
            vector = np.array((1, 0))
        return vector

    def stop(self, goal, collision):
        return self.hindbrain.stop(self.body.coods, self.body.velocity)

    def get_goal_vector(self, list_of_game_objects):
        goal = self.goal_getter.goal_position(self.action)
        collision = self.eyes.look_for_collisions(self.body.coords,
                                                  self.body.velocity,
                                                  self.self_image['radius'])
        if goal is not None:
            if self.action.behaviour() == 'seek':
                vector = self.seek(goal, collision)
            elif self.action.behaviour() == 'flee':
                vector = self.flee(goal, collision)
            elif self.action.behaviour() == 'stop':
                vector = self.stop(goal, collision)
        else:
            vector = self.wander(goal, collision)
        return vector
예제 #11
0
from eyes import Eyes
from colorama import Style

if __name__ == '__main__':
    try:
        print(Eyes.banner())
        print(Eyes.menu())
        print('')
        Eyes.eyes()
    except KeyboardInterrupt:
        print("\nBye")
        print(Style.RESET_ALL)
        exit(0)
else:
    from api import API
#!/usr/bin/env python3
from datetime import datetime
from models import *
from eyes import Eyes
from minerador import Minerador
import os
import time

eyes = Eyes(True)
eyes.auth()
miner = Minerador(eyes)
reauth_in = 10
aux_reauth = 1

processos = Processo.select().where(Processo.data_autuacao == None)
for processo in processos.iterator(database):
    sigilo = True
    print('{} Obtendo {}'.format(datetime.now(), processo.numero))
    try:
        miner.get_processo(processo.numero)
        data = miner.get_data()
        miner.get_files(data['eventos'])
    except Exception as e:
        print('Falha ao obter dados do processo: {} \n e: {}'.format(
            processo.numero, str(e)))
        eyes.takeSs()
        print('Screenshot salva')
        continue

    try:
        for k, v in data['adicionais'].items():
예제 #13
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Face Tracker main application
"""

# Importing packages
from servo import Servo
from eyes import Eyes
from cv2 import waitKey
import time

# Create objects
camera = Eyes()
body = Servo()

outX = 90
outY = 90


def translate(x, lowerIn, upperIn, lowerOut, upperOut):
    """Map in value range to another range"""
    y = (x - lowerIn) / (upperIn - lowerIn) * (upperOut - lowerOut) + lowerOut
    return y


def millis():
    """ Returns current time in milliseconds."""
    return int(round(time.time() * 1000))

예제 #14
0
import RPi.GPIO as GPIO

logging.basicConfig(level=logging.DEBUG,
                    format='(%(threadName)-10s) %(asctime)s %(message)s',
                    )

scaring = threading.Event()
doneplaying = threading.Event()
closedevent = threading.Event()
closedevent.set()
openevent = threading.Event()

light = Light(args=('74:DA:EA:90:FD:87',))
spk = Speaker(args=('/home/pi/sounds',doneplaying))

eyes = Eyes(args=(), kwargs={'lefteye': 12, 'righteye': 13})

def open_callback():
    logging.info('Open callback')
    openevent.set()

    if scaring.is_set():
        spk.cancel()

    # threading.Timer(5, lambda: eyes.turnoff()).start()
    eyes.turnoff()
    light.fullon()
    
def close_callback():
    openevent.clear()
    logging.info('Turning light back "on"')
예제 #15
0
class Pinky(GameCharacter):
    def __init__(self, maze, pacman, game_controller):
        self.CHAR_WIDTH = 100
        self.CHAR_HEIGHT = 100
        self.maze = maze
        self.pacman = pacman
        self.gc = game_controller
        self.x = maze.WIDTH/2
        self.y = maze.TOP_HORIZ
        self.velocity = 2
        self.x_add = self.velocity
        self.y_add = 0
        self.eyes = Eyes()
        self.looking = (0, 0)
        self.WIN_PROXIMITY = 80
        self.WALL_TOLERANCE = 2

    def draw_self(self, x, y):
        """Draw Pinky to the screen"""
        noStroke()
        fill(1.0, 0.5, 0.6)
        ellipse(x, y, 100, 100)
        bottom_half = createShape()
        bottom_half.beginShape()
        bottom_half.vertex(x, y)
        bottom_half.vertex(x+100, y)
        bottom_half.vertex(x+100, y+50)
        bottom_half.vertex(x+50, y+25)
        bottom_half.vertex(x, y+50)
        bottom_half.endShape()
        shape(bottom_half, -50, 0)

        self.eyes.display(x, y - 15, self.looking)

    def update(self):
        """Carry out necessary updates for each frame before
        drawing to screen"""
        # Check if Pinky is at an intersection
        on_vert = (
            (abs(self.x - self.maze.LEFT_VERT) < self.WALL_TOLERANCE) or
            (abs(self.x - self.maze.RIGHT_VERT) < self.WALL_TOLERANCE)
                   )
        on_horz = (
            (abs(self.y - self.maze.TOP_HORIZ) < self.WALL_TOLERANCE) or
            (abs(self.y - self.maze.BOTTOM_HORIZ) < self.WALL_TOLERANCE)
                   )

        # Check whether Pinky is up or down/left or right of Pacman
        up_down_part = self.pacman.y - self.y
        left_right_part = self.pacman.x - self.x

        # Update Pinky's eyes to look at Pacman
        self.update_eyes(up_down_part, left_right_part)

        # If Pinky gets close to Pacman, tell the GameController
        # that Pinky wins
        if (abs(up_down_part) < self.WIN_PROXIMITY and
                abs(left_right_part) < self.WIN_PROXIMITY):
            self.gc.pinky_wins = True

        # When Pinky is in the intersection, it needs to decide where to go
        # based on Pacman's position
        if on_vert and on_horz:
            # When Pinky and Pacman are in the same column,
            # check the x_distance of Pinky and Pacman,
            # and decide the path the Pinky will go
            if up_down_part == 0:
                if left_right_part > 0:
                    self.x_add = self.velocity
                    self.y_add = 0
                else:
                    self.x_add = - self.velocity
                    self.y_add = 0
            # When Pinky and Pacman are in the same row,
            # check the y_distance of Pinky and Pacman,
            # and decide the path the Pinky will go
            if left_right_part == 0:
                if up_down_part > 0:
                    self.x_add = 0
                    self.y_add = self.velocity
                else:
                    self.x_add = 0
                    self.y_add = -self.velocity
            # When Pinky and Pacman are not in the same row, and not in the
            # same column
            else:
                # if Pinky is in the upper left part, and Pacman in the lower
                # right part, Pinky will move on the right first
                if up_down_part > 0 and left_right_part > 0:
                    self.x_add = self.velocity
                    self.y_add = 0
                # if Pinky is in the upper right part, and Pacman in the lower
                # left part, Pinky will move down vertically first
                if up_down_part > 0 and left_right_part < 0:
                    self.x_add = 0
                    self.y_add = self.velocity
                # if Pinky is in the down left part, and Pacman in the upper
                # right part, Pinky will move up vertically first
                if up_down_part < 0 and left_right_part > 0:
                    self.x_add = 0
                    self.y_add = -self.velocity
                # if Pinky is in the down right part, and Pacman in the upper
                # left part, Pinky will move left first
                if up_down_part < 0 and left_right_part < 0:
                    self.x_add = -self.velocity
                    self.y_add = 0

        if self.gc.player_wins:
            self.x_add = 0
            self.y_add = 0

        # Move Pinky
        self.x = self.x + self.x_add
        self.y = self.y + self.y_add

    def update_eyes(self, up_down_part, left_right_part):
        """Set self.looking value based on position of Pinky w/r/t Pacman"""
        if up_down_part and abs(up_down_part) > 5:
            y = up_down_part/abs(up_down_part)
        else:
            y = 0
        if left_right_part and abs(left_right_part) > 5:
            x = left_right_part/abs(left_right_part)
        else:
            x = 0
        self.looking = (x, y)
예제 #16
0
class Pinky(GameCharacter):
    def __init__(self, maze, pacman, game_controller):
        self.CHAR_WIDTH = 100
        self.CHAR_HEIGHT = 100
        self.maze = maze
        self.pacman = pacman
        self.gc = game_controller
        self.x = maze.WIDTH / 2
        self.y = maze.TOP_HORIZ
        self.velocity = 2
        self.x_add = self.velocity
        self.y_add = 0
        self.eyes = Eyes()
        self.looking = (0, 0)
        self.WIN_PROXIMITY = 80
        self.WALL_TOLERANCE = 2

    def draw_self(self, x, y):
        """Draw Pinky to the screen"""
        noStroke()
        fill(1.0, 0.5, 0.6)
        ellipse(x, y, 100, 100)
        bottom_half = createShape()
        bottom_half.beginShape()
        bottom_half.vertex(x, y)
        bottom_half.vertex(x + 100, y)
        bottom_half.vertex(x + 100, y + 50)
        bottom_half.vertex(x + 50, y + 25)
        bottom_half.vertex(x, y + 50)
        bottom_half.endShape()
        shape(bottom_half, -50, 0)

        self.eyes.display(x, y - 15, self.looking)

    def update(self):
        """Carry out necessary updates for each frame before
        drawing to screen"""
        # Check if Pinky is at an intersection
        on_vert = ((abs(self.x - self.maze.LEFT_VERT) < self.WALL_TOLERANCE) or
                   (abs(self.x - self.maze.RIGHT_VERT) < self.WALL_TOLERANCE))
        on_horz = (
            (abs(self.y - self.maze.TOP_HORIZ) < self.WALL_TOLERANCE)
            or (abs(self.y - self.maze.BOTTOM_HORIZ) < self.WALL_TOLERANCE))

        # Check whether Pinky is up or down/left or right of Pacman
        up_down_part = self.pacman.y - self.y
        left_right_part = self.pacman.x - self.x

        # Update Pinky's eyes to look at Pacman
        self.update_eyes(up_down_part, left_right_part)

        # If Pinky gets close to Pacman, tell the GameController
        # that Pinky wins
        if (abs(up_down_part) < self.WIN_PROXIMITY
                and abs(left_right_part) < self.WIN_PROXIMITY):
            self.gc.pinky_wins = True

        # TODO:
        # PROBLEM 2: Make Pinky chase Pacman!
        # Study the code above and below these lines to understand how
        # Pinky's movements are calculated, and how Pinky's position with
        # respect to Pacman is represented.
        # Pinky should decide at each intersection whether to go left, right
        # up or down depending on which direction Pacman is further away in.
        # START CODE CHANGES
        on_intersection = on_horz and on_vert
        if self.pacman.x_add == 0 and self.pacman.y_add == 0:
            self.x_add = self.velocity
            self.y_add = 0
        else:
            if left_right_part and up_down_part and on_intersection:
                print("intersection")
                if abs(up_down_part) < abs(left_right_part):
                    self.x_add = left_right_part / \
                        abs(left_right_part) * self.velocity
                    self.y_add = 0
                else:
                    self.y_add = up_down_part / \
                        abs(up_down_part) * self.velocity
                    self.x_add = 0
            elif up_down_part and on_vert:
                self.y_add = up_down_part / abs(up_down_part) * self.velocity
                self.x_add = 0

            elif left_right_part and on_horz:
                self.x_add = left_right_part / \
                    abs(left_right_part) * self.velocity
                self.y_add = 0

        # END CODE CHANGES

        # If the player wins, stop Pinky moving
        if self.gc.player_wins:
            self.x_add = 0
            self.y_add = 0

        # Move Pinky
        self.x = self.x + self.x_add
        self.y = self.y + self.y_add

    def update_eyes(self, up_down_part, left_right_part):
        """Set self.looking value based on position of Pinky w/r/t Pacman"""
        if up_down_part and abs(up_down_part) > 5:
            y = up_down_part / abs(up_down_part)
        else:
            y = 0
        if left_right_part and abs(left_right_part) > 5:
            x = left_right_part / abs(left_right_part)
        else:
            x = 0
        self.looking = (x, y)
예제 #17
0
from eyes import Eyes
import pprint

e = Eyes()
e.auth()

e.searchProcesso("5002074-02.2015.404.7005")
# e.acessarIntegra()
# e.exibirTodosEventos()
# print(e.getAdicionais())
# teste = e.getCapa()
# print(teste)
# e.getAssuntos()
# print(e.getPartes())
# eventos = e.getEventos()
# pprint.pprint(eventos)
# for ev in eventos:
# 	# pprint.pprint(ev['documentos'])
# 	if ev['documentos']:
# 		for doc in ev['documentos']:
# 			if doc['tipo'] == 'html':
# 				e.download_html(doc['url'], doc['nome'])
# 			elif doc['tipo'] == 'pdf':
# 				e.download_pdf(doc['url'], doc['nome'])
# 				input("Press Enter to continue...")
# 			# doc[]
e.close()
예제 #18
0
# Drawing stuff
font = cv2.FONT_HERSHEY_SIMPLEX

# Wait until user specifies windows dimensions
while len(mouseevents.clicked_positions) < 2:
    pass

# Load settings
with open('settings.json', 'r') as f:
    SETTINGS = json.load(f)

# ROI for game window
ROI_GAME = get_roi_from_mouse(mouseevents.clicked_positions)

# Our eyes for the game
eye = Eyes(ROI_GAME, SETTINGS)
eye.tune_roi()

# Extra
print('[!] Calibration complete')
print('[!] Loading model')

# Loading trained model
with open('model.pkl', 'rb') as fid:
    clf = cPickle.load(fid)

print('[!] Loaded model')
print('[!] Press "q" to quit')
print('[.] Please get ready')
print('[!] Press "c" to continue')
while not keyevents.pressed_c:
예제 #19
0
def eyes_py(id):
    global sidebudsPosX, sidebudsPosY, dispar, sadws

    # 初期化宣言 : このソフトウェアは"eyes_py_node"という名前
    rospy.init_node('eyes_py_node', anonymous=True)

    # インスタンスの作成
    eyes = Eyes(id)

    # 処理周期の設定
    r = rospy.Rate(PUB_RATE)

    print("[eyes2] start")
    # ctl + Cで終了しない限りwhileループで処理し続ける
    while not rospy.is_shutdown():

        #==================================================
        # Loop
        ret0, imgL = RP3_Cap_L.read()
        ret1, imgR = RP3_Cap_R.read()

        if dispMode == 1:
            cv2.imshow("Left  Camera", imgL)
            cv2.imshow("Right Camera", imgR)

        #-- Create DiparityMap --
        disparity = GetDisparityMap()

        ###################################################
        #-- Look for SideBuds --
        sbsJpg = cv2.imread('./SideBuds_1.JPG', 0)

        grayImg = cv2.cvtColor(imgL, cv2.COLOR_BGR2GRAY)

        result = cv2.matchTemplate(grayImg, sbsJpg, cv2.TM_CCOEFF_NORMED)
        unused_minVal, unused_maxVal, unused_minLoc, maxLoc = cv2.minMaxLoc(
            result)
        top_left = maxLoc
        w, h = sbsJpg.shape[::-1]
        bottom_right = (top_left[0] + w, top_left[1] + h)

        if dispMode == 1:
            cv2.rectangle(imgL, top_left, bottom_right, (0, 255, 0), 1)
            cv2.imshow("SideBuds", imgL)

        sidebudsPosX = top_left[0] + (w / 2)
        sidebudsPosY = top_left[1] + (h / 2)

        #-- Cal SideBuds Distance --
        sidebudsPosDist = 6.6 * 62 / 0.003 / disparity[sidebudsPosY][
            sidebudsPosX]
        print sidebudsPosX, sidebudsPosY, sidebudsPosDist

        ###################################################
        #-- Cal weed Center --
        targetL = GetGreenDetect(imgL)
        targetR = GetGreenDetect(imgR)

        # target Position
        Lx, Ly, Lw, Lh = cv2.boundingRect(targetL)
        Rx, Ry, Rw, Rh = cv2.boundingRect(targetR)

        if dispMode == 1:
            cv2.rectangle(imgL, (Lx, Ly), (Lx + Lw, Ly + Lh), (0, 0, 255), 1)
            cv2.imshow("Weed L", imgL)
            cv2.rectangle(imgR, (Rx, Ry), (Rx + Rw, Ry + Rh), (0, 0, 255), 1)
            cv2.imshow("Weed R", imgR)

        # Xは左右中心の更に中心
        Lpos = Lx + (Lw / 2)
        Rpos = Rx + (Rw / 2)
        weedPosX = (Lpos + Rpos) / 2
        # Yは片側基準でOK
        weedPosY = Ly + (Lh / 2)

        # from disparity to dist
        # Z = f x T / um / disparity
        weedPosDist = 6.6 * 62 / 0.003 / disparity[weedPosY][weedPosX]
        print weedPosX, weedPosY, weedPosDist

        #==================================================
        # メイン処理
        eyes.main()

        # Sleep処理
        r.sleep()
예제 #20
0
keyevents.start()
mouseevents.start()

# Wait until user specifies windows dimensions
while len(mouseevents.clicked_positions) < 2:
    pass

# Load settings
with open('settings.json', 'r') as f:
    SETTINGS = json.load(f)

# ROI for game window
ROI_GAME = get_roi_from_mouse(mouseevents.clicked_positions)

# Our eyes for the game
eye = Eyes(ROI_GAME, SETTINGS, preview=True)
eye.tune_roi()

# Extra ubfi
print('[!] Calibration complete')
print('[!] Press "q" to quit')
print('[.] Please get ready')

# Time for user to get anything ready
print('[!] Press "c" to continue')
while not keyevents.pressed_c:
    pass

print('[!] Starting...')
keyevents.end = False
예제 #21
0
class Pinky(GameCharacter):
    def __init__(self, maze, pacman, game_controller):
        self.CHAR_WIDTH = 100
        self.CHAR_HEIGHT = 100
        self.maze = maze
        self.pacman = pacman
        self.gc = game_controller
        self.x = maze.WIDTH/2
        self.y = maze.TOP_HORIZ
        self.velocity = 2
        self.x_add = self.velocity
        self.y_add = 0
        self.eyes = Eyes()
        self.looking = (0, 0)
        self.WIN_PROXIMITY = 80
        self.WALL_TOLERANCE = 2
        self.maze_graph = [[0,300,300,float('inf'),float('inf')],
                           [300,0,float('inf'),300,float('inf')],
                           [300,float('inf'),0,300,float('inf')],
                           [float('inf'),300,300,0,float('inf')], 
                           [float('inf'),float('inf'),float('inf'),float('inf'),0]]

    def draw_self(self, x, y):
        """Draw Pinky to the screen"""
        noStroke()
        fill(1.0, 0.5, 0.6)
        ellipse(x, y, 100, 100)
        bottom_half = createShape()
        bottom_half.beginShape()
        bottom_half.vertex(x, y)
        bottom_half.vertex(x+100, y)
        bottom_half.vertex(x+100, y+50)
        bottom_half.vertex(x+50, y+25)
        bottom_half.vertex(x, y+50)
        bottom_half.endShape()
        shape(bottom_half, -50, 0)

        self.eyes.display(x, y - 15, self.looking)

    def update(self):
        """Carry out necessary updates for each frame before
        drawing to screen"""

        # Check whether Pinky is up or down/left or right of Pacman
        up_down_part = self.pacman.y - self.y
        left_right_part = self.pacman.x - self.x

        # Update Pinky's eyes to look at Pacman
        self.update_eyes(up_down_part, left_right_part)

        # If Pinky gets close to Pacman, tell the GameController
        # that Pinky wins
        if (abs(up_down_part) < self.WIN_PROXIMITY and
                abs(left_right_part) < self.WIN_PROXIMITY):
            self.gc.pinky_wins = True

        # If the player wins, stop moving Pinky
        if self.gc.player_wins:
            self.x_add = 0
            self.y_add = 0

        # Move Pinky if at an intersection:
        if self.x == self.maze.LEFT_VERT:
            if self.y >= self.maze.BOTTOM_HORIZ - self.WALL_TOLERANCE\
            and self.y <= self.maze.BOTTOM_HORIZ + self.WALL_TOLERANCE:
                self.update_graph()
                self.move_Pinky(2, self.dijkstras(2), up_down_part, left_right_part)
            elif self.y >= self.maze.TOP_HORIZ - self.WALL_TOLERANCE\
            and self.y <= self.maze.TOP_HORIZ + self.WALL_TOLERANCE:
                self.update_graph()
                self.move_Pinky(0, self.dijkstras(0), up_down_part, left_right_part)
        
        elif self.x == self.maze.RIGHT_VERT:
            if self.y >= self.maze.BOTTOM_HORIZ - self.WALL_TOLERANCE\
            and self.y <= self.maze.BOTTOM_HORIZ + self.WALL_TOLERANCE:
                self.update_graph()
                self.move_Pinky(3, self.dijkstras(3), up_down_part, left_right_part)
            elif self.y >= self.maze.TOP_HORIZ - self.WALL_TOLERANCE\
            and self.y <= self.maze.TOP_HORIZ + self.WALL_TOLERANCE:
                self.update_graph()
                self.move_Pinky(1, self.dijkstras(1), up_down_part, left_right_part)
        
        elif self.y == self.maze.BOTTOM_HORIZ:
            if self.x >= self.maze.LEFT_VERT - self.WALL_TOLERANCE\
            and self.x <= self.maze.LEFT_VERT + self.WALL_TOLERANCE:
                self.update_graph()
                self.move_Pinky(2, self.dijkstras(2), up_down_part, left_right_part)
            elif self.x >= self.maze.RIGHT_VERT - self.WALL_TOLERANCE\
            and self.x <= self.maze.RIGHT_VERT + self.WALL_TOLERANCE:
                self.update_graph()
                self.move_Pinky(3, self.dijkstras(3), up_down_part, left_right_part)
        
        elif self.y == self.maze.TOP_HORIZ:
            if self.x >= self.maze.LEFT_VERT - self.WALL_TOLERANCE\
            and self.x <= self.maze.LEFT_VERT + self.WALL_TOLERANCE:
                self.update_graph()
                self.move_Pinky(0, self.dijkstras(0), up_down_part, left_right_part)
            elif self.x >= self.maze.RIGHT_VERT - self.WALL_TOLERANCE\
            and self.x <= self.maze.RIGHT_VERT + self.WALL_TOLERANCE:
                self.update_graph()
                self.move_Pinky(1, self.dijkstras(1), up_down_part, left_right_part)
        
        self.x = self.x + self.x_add
        self.y = self.y + self.y_add

    def move_Pinky(self, current, next, up_down_part, left_right_part):
        # if there is a direct path to catch Pacman, go directly towards him
        if next == 4:
            if up_down_part == 0:
                if current == 2:
                    if left_right_part > 0:
                        self.x_add = self.velocity
                        self.y_add = 0
                    else:
                        self.x_add = -self.velocity
                        self.y_add = 0
                elif current == 3:
                    if left_right_part < 0:
                        self.x_add = -self.velocity
                        self.y_add = 0
                    else:
                        self.x_add = self.velocity
                        self.y_add = 0
                elif current == 0:
                    if left_right_part > 0:
                        self.x_add = self.velocity
                        self.y_add = 0
                    else:
                        self.x_add = -self.velocity
                        self.y_add = 0
                else:
                    if left_right_part < 0:
                        self.x_add = -self.velocity
                        self.y_add = 0
                    else:
                        self.x_add = self.velocity
                        self.y_add = 0
            
            else:
                if current == 2:
                    if up_down_part > 0:
                        self.x_add = 0
                        self.y_add = self.velocity
                    else:
                        self.x_add = 0
                        self.y_add = -self.velocity
                elif current == 3:
                    if up_down_part > 0:
                        self.x_add = 0
                        self.y_add = self.velocity
                    else:
                        self.x_add = 0
                        self.y_add = -self.velocity
                elif current == 0:
                    if up_down_part < 0:
                        self.x_add = 0
                        self.y_add = -self.velocity
                    else:
                        self.x_add = 0
                        self.y_add = self.velocity
                else:
                    if up_down_part < 0:
                        self.x_add = 0
                        self.y_add = -self.velocity
                    else:
                        self.x_add = 0
                        self.y_add = self.velocity
        # if there's no direct path to pacman, follow the shortest path
        else:
            if current == 0:
                if next == 1:
                    self.x_add = self.velocity
                    self.y_add = 0
                else:
                    self.x_add = 0
                    self.y_add = -self.velocity

            elif current == 1:
                if next == 0:
                    self.x_add = -self.velocity
                    self.y_add = 0
                else:
                    self.x_add = 0
                    self.y_add = -self.velocity

            elif current == 2:
                if next == 0:
                    self.x_add = 0
                    self.y_add = self.velocity
                else:
                    self.x_add = self.velocity
                    self.y_add = 0

            elif current == 3:
                if next == 1:
                    self.x_add = 0
                    self.y_add = self.velocity
                else:
                    self.x_add = -self.velocity
                    self.y_add = 0

    def update_graph(self):
        pacman_edges = [float('inf'),float('inf'),float('inf'),float('inf'),0]
        pacman_x = self.pacman.x
        pacman_y = self.pacman.y
        left_vert = self.maze.LEFT_VERT
        right_vert = self.maze.RIGHT_VERT
        bottom_horiz = self.maze.BOTTOM_HORIZ
        top_horiz = self.maze.TOP_HORIZ

        # Pacman is on bottom row
        if pacman_y == bottom_horiz:
            if pacman_x >= left_vert and pacman_x <= right_vert:
                pacman_edges[2] = pacman_x - left_vert
                pacman_edges[3] = right_vert - pacman_x
            elif pacman_x < left_vert:
                pacman_edges[2] = left_vert - pacman_x
                pacman_edges[3] = left_vert + (left_vert - pacman_edges[2])
            else:
                pacman_edges[3] = pacman_x - right_vert
                pacman_edges[2] = left_vert + (left_vert - pacman_edges[3])
        # Pacman is on top row
        elif pacman_y == top_horiz:
            if pacman_x >= left_vert and pacman_x <= right_vert:
                pacman_edges[0] = pacman_x - left_vert
                pacman_edges[1] = right_vert - pacman_x
            elif pacman_x < left_vert:
                pacman_edges[0] = left_vert - pacman_x
                pacman_edges[1] = left_vert + (left_vert - pacman_edges[0])
            else:
                pacman_edges[1] = pacman_x - right_vert
                pacman_edges[0] = left_vert + (left_vert - pacman_edges[1])
        # Pacman is on left column
        if pacman_x == left_vert:
            if pacman_y >= bottom_horiz and pacman_y <= top_horiz:
                pacman_edges[2] = pacman_y - bottom_horiz
                pacman_edges[0] = top_horiz - pacman_y
            elif pacman_y < bottom_horiz:
                pacman_edges[2] = bottom_horiz - pacman_y
                pacman_edges[0] = bottom_horiz + (bottom_horiz - pacman_edges[2])
            else:
                pacman_edges[0] = pacman_x - top_horiz
                pacman_edges[2] = bottom_horiz + (bottom_horiz - pacman_edges[0])
        # Pacman is on right column
        elif pacman_x == right_vert:
            if pacman_y >= bottom_horiz and pacman_y <= top_horiz:
                pacman_edges[3] = pacman_y - bottom_horiz
                pacman_edges[1] = top_horiz - pacman_y
            elif pacman_y < bottom_horiz:
                pacman_edges[3] = bottom_horiz - pacman_y
                pacman_edges[1] = bottom_horiz + (bottom_horiz - pacman_edges[3])
            else:
                pacman_edges[1] = pacman_x - top_horiz
                pacman_edges[3] = bottom_horiz + (bottom_horiz - pacman_edges[1])

        for i in range(len(pacman_edges) - 1):
            self.maze_graph[i][-1] = pacman_edges[i]
        
        self.maze_graph[-1] = pacman_edges

    def dijkstras(self, s):
        dist = [ float('inf') for _ in range(len(self.maze_graph)) ]
        parent = [ -1 for _ in range(len(self.maze_graph)) ]
        n = set()
        dist[s] = 0
        while len(n) != len(self.maze_graph):
            u = self.select_min(dist, n)
            n.add(u)
            for v in range(len(self.maze_graph)):
                if self.maze_graph[u][v] != float('inf'):
                    self.relax(dist, parent, u, v)
        next_destination = 4
        while parent[next_destination] != -1:
            next_destination = parent[next_destination]
        if next_destination == parent[4]:
            return 4
        next_destination = 4
        while parent[next_destination] != s:
            next_destination = parent[next_destination]
        return next_destination

    def select_min(self, dist, n):
        min_dist = float('inf')
        min_dist_vertex = -1
        for vertex in range(len(dist)):
            if vertex not in n and dist[vertex] < min_dist:
                min_dist = dist[vertex]
                min_dist_vertex = vertex
        return min_dist_vertex

    def relax(self, dist, parent, u, v):
        if dist[u] + self.maze_graph[u][v] < dist[v]:
            dist[v] = dist[u] + self.maze_graph[u][v]
            parent[v] = u


    def update_eyes(self, up_down_part, left_right_part):
        """Set positioning of Pinky's eyes based on Pac-Man's coordinates"""
        if up_down_part and abs(up_down_part) > 5:
            y = up_down_part/abs(up_down_part)
        else:
            y = 0
        if left_right_part and abs(left_right_part) > 5:
            x = left_right_part/abs(left_right_part)
        else:
            x = 0
        self.looking = (x, y)
예제 #22
0
파일: robot.py 프로젝트: rcschen/chungtao
 def __init__(self, kickstart):
     self.eyes = Eyes(kickstart)
     self.brain = Brain(kickstart)
     self.feet = WheelFeet(kickstart)
     super(Chuntao, self).__init__()
예제 #23
0
def capture_action(pred_path, cb, debug=False, log=False):
    """Facial detection and real time processing credit goes to:

    https://www.pyimagesearch.com/2017/04/17/real-time-facial-landmark-detection-opencv-python-dlib/
    """
    action_handler = ActionHandler()

    detector = dlib.get_frontal_face_detector()
    predictor = dlib.shape_predictor(pred_path)

    camera = cv2.VideoCapture(0)

    while True:
        _, frame = camera.read()
        if frame is None:
            continue

        _, w_original, _ = frame.shape
        frame = resize_frame(frame)

        h, w, _ = frame.shape

        display_bounds(frame)

        gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        rects = detector(gray, 0)

        for rect in rects:
            shape = predictor(gray, rect)
            shape = face_utils.shape_to_np(shape)

            cur_head = Head(shape, w)
            cur_eyes = Eyes(shape, frame)

            eye_action = detect_eyes(shape, cur_eyes)
            head_action = detect_head(shape, cur_head)

            COUNTER_LOG[eye_action] += 1
            COUNTER_LOG[head_action] += 1

            perform, action = action_handler.get_next(eye_action, head_action)

            if log:
                display_decisions(frame, head_action, eye_action)
                display_counters(frame, COUNTER_LOG)

            if perform:
                COUNTER_LOG[action] += 1
                cb(action)

            if debug:
                cur_head.debug(frame)
                cur_eyes.debug(frame)

                cv2.imshow("Frame", frame)

        key = cv2.waitKey(1) & 0xFF

        if key == ord("q"):
            break

    cv2.destroyAllWindows()
예제 #24
0
파일: app.py 프로젝트: tak75/eye_draw
# -*- coding: UTF-8 -*-

from eyes import Eyes

eyes = Eyes()

while True:
    # 普通
    eyes.set_nomal()
    # 怒り
    for level in range(1,11,1):
        eyes.set_anger(level)
    for level in range(10,0,-1):
        eyes.set_anger(level)
    # 普通
    eyes.set_nomal()
    # 驚き
    for level in range(5,0,-1):
        eyes.set_surprized(level)
    for level in range(1,6,1):
        eyes.set_surprized(level)