Пример #1
0
 def test_check_goban_moved_false0(self):
     corners_img1, corners_img2 = self.select_corners_false(0)
     assert_false(check_goban_moved(corners_img1, corners_img2))
Пример #2
0
def main(parser):

    print "Camer, video, record"
    print parser.camera
    print parser.video
    print parser.record

    if parser.camera:
        cam = Cameras()
        cams_found = cam.check_cameras(int(parser.camera))
        camera = cam.show_and_select_camera()
        # TODO
        threshold = 190
    elif parser.video:
        camera = CaptureFromFile(parser.video)
        threshold = 150
    if parser.record:
        record = Record(parser.record, QueryFrame(camera))

    prev_corners = None
    current_corners = None
    good_corners = None
    ideal_img = None
    goban = Goban(GOBAN_SIZE)

    while camera:
        # Select image from camera
        # TODO
        # img = camera.get_frame()
        img = QueryFrame(camera)  # Test videos
        if parser.record:
            record.add_frame(img)

        # previous corners
        prev_corners = copy(current_corners)

        # Detect goban
        current_corners = search_goban(img)
        if not current_corners:
            current_corners = copy(prev_corners)

        # Check goban moved
        if check_goban_moved(prev_corners, current_corners):
            good_corners = copy(current_corners)
            # print "MOVED"

        if good_corners:
            # Paint corners for tested
            for corner in good_corners:
                Circle(img, corner, 4, (255, 0, 0), 4, 8, 0)
            # Transform goban to ideal form
            ideal_img = perspective(img, good_corners)  # TODO no hallar 2 veces

        if ideal_img:
            circles = search_stones(ideal_img, good_corners)
            false_stones = 0
            stones = []
            for n in range(circles.cols):
                pixel = Get1D(circles, n)
                pt = (Round(pixel[0]), Round(pixel[1]))
                radious = Round(pixel[2])
                # Comprobar el color en la imagen
                color = check_color_stone(pt, radious, ideal_img, threshold)
                if color == BLACK:
                    # print "BLACK"
                    Circle(ideal_img, pt, radious, CV_RGB(255, 0, 0), 2)
                    stones.append(Stone(color, img=ideal_img, pix=pt))
                elif color == WHITE:
                    # print "WHITE"
                    Circle(ideal_img, pt, radious, CV_RGB(0, 255, 0), 2)
                    stones.append(Stone(color, img=ideal_img, pix=pt))
                else:
                    # Circle(ideal_img, pt, radious, CV_RGB(255,255,0),2)
                    false_stones += 1

            # print "Hay %d piedras. " %(circles.cols - false_stones)
            # Añadimos las piedras para trabajar con ellas estadísticamente
            goban.add_stones_to_statistical(stones)

            ShowImage("Ideal", ideal_img)

        # Show image
        ShowImage("Camera", img)

        # Detect stone

        # Upload to internet

        # FPS
        key = WaitKey(1)
        if key == 27:  # Esc
            goban.kifu.end_file()
            goban.igs.close()
            break
Пример #3
0
 def test_check_goban_moved_true3(self):
     corners_img1, corners_img2 = self.select_corners_true(3)
     assert_true(check_goban_moved(corners_img1, corners_img2))