예제 #1
0
def board(args):
    global nao_motion
    data.IP = args['--ip']
    data.PORT = int(args['--port'])
    next_img_func = get_nao_image
    if args['--no-robot']:
        next_img_func = get_webcam_image
    myc4 = Connect4Handler(next_img_func, cam_no=int(args['--cam-no']))
    dist = float(args['--dist'])
    sloped = args['--sloped']
    tries = int(args['--min-detections'])
    nao_motion = MotionController()
    nao_motion.lookAtGameBoard(dist)
    while True:
        try:
            myc4.detectFrontHoles(dist, sloped, tries=tries)
            cv2.imshow("Connect 4 Perspective", myc4.front_hole_detector.getPerspective())
        except FrontHolesGridNotFoundException:
            pass
        img2 = draw_circles(myc4.img, myc4.circles)
        cv2.imshow("Circles detected", img2)
        cv2.imshow("Original picture", myc4.img)
        if cv2.waitKey(10) == 27:
            print "Esc pressed : exit"
            close_camera()
            break
    return 0
예제 #2
0
def state(args):
    global nao_motion
    print
    print "-1 = Empty, 0 = Red, 1 = Green"
    print
    data.IP = args['--ip']
    data.PORT = int(args['--port'])
    next_img_func = get_nao_image
    if args['--no-robot']:
        next_img_func = get_webcam_image
    myc4 = Connect4Handler(next_img_func, cam_no=int(args['--cam-no']))
    dist = float(args['--dist'])
    sloped = args['--sloped']
    tries = int(args['--min-detections'])

    ref_mapping = DefaultConnect4Image().generate2DReference()
    strategy = NAOVision(ref_mapping, lambda: perspective)

    strategy.player_id = disc.GREEN
    test_state = C4State()
    nao_motion = MotionController()
    nao_motion.lookAtGameBoard(dist)
    while True:
        try:
            myc4.detectFrontHoles(dist, sloped, tries=tries)
            perspective = myc4.front_hole_detector.getPerspective()
            if not args['--no-image']:
                cv2.imshow("Perspective", perspective)
            game_state = strategy.analyseFullImage(test_state, img=perspective, debug=True)
            print game_state
            print
        except BaseException:
            pass
        if cv2.waitKey(1) == 27:
            print "Esc pressed : exit"
            close_camera()
            break
        sleep(0.5)