Beispiel #1
0
class Test_camera(unittest.TestCase):
    def setUp(self):
        self.cameras = Cameras()
        self.camera_1 = Camera()
        self.camera_2 = Camera()

    def tearDown(self):
        self.cameras = None

    def test_select_zero_cameras(self):
        result = self.cameras.show_and_select_camera()
        assert_equals(result, None)

    def test_select_one_cameras(self):
        self.cameras.cameras = [self.camera_1]
        result = self.cameras.show_and_select_camera()
        assert_equals(result, self.camera_1)

    def test_select_two_or_more_cameras(self):
        self.cameras.cameras = [self.camera_1, self.camera_2]
        self.cameras.camera = choice(self.cameras.cameras)
        result = self.cameras.show_and_select_camera()
        assert_true(result in self.cameras.cameras)
Beispiel #2
0
class Test_camera(unittest.TestCase):
    
    def setUp(self):
        self.cameras = Cameras()
        self.camera_1 = Camera()
        self.camera_2 = Camera()
    
    def tearDown(self):
        self.cameras = None
    
    def test_select_zero_cameras(self):
        result = self.cameras.show_and_select_camera()
        assert_equals(result, None)
    
    def test_select_one_cameras(self):
        self.cameras.cameras = [self.camera_1]
        result = self.cameras.show_and_select_camera()
        assert_equals(result, self.camera_1)

    def test_select_two_or_more_cameras(self):
        self.cameras.cameras = [self.camera_1, self.camera_2]
        self.cameras.camera = choice(self.cameras.cameras)
        result = self.cameras.show_and_select_camera()
        assert_true(result in self.cameras.cameras)
Beispiel #3
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
Beispiel #4
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