Exemplo n.º 1
0
    def __init__(self,
                 angles_num,
                 user_moves_if_test=None,
                 rival_moves_if_test=None,
                 imgs_if_test=None,
                 if_save_and_print=True,
                 net_dir_name=None,
                 save_idx=0):

        global RESULTS_DIR
        # mygui.init()
        RESULTS_DIR += str(net_dir_name)
        # if ('super_tester_results' + str(net_dir_name)) in os.listdir("professional games 3"):
        #     raise Exception("berkos exception. change the name of the folder")
        tester_helper.RESULTS_DIR += str(net_dir_name)
        if net_dir_name:
            net_dir_name = os.path.join(RESULTS_DIR, str(net_dir_name))
        else:
            net_dir_name = None
        self.if_save = if_save_and_print
        if self.if_save:
            tester_helper.make_minimal_squares_dirs()
        self.moves_counter = 0
        self.last_move = None

        if user_moves_if_test is not None:
            self.is_test = True
            self.incon_cnt = 0
            self.corrects_cnt = 0
            self.net_dir_name = net_dir_name
            self.user_moves = user_moves_if_test
            self.rival_moves = rival_moves_if_test
            if imgs_if_test:
                self.is_live_test = False
            else:
                self.is_live_test = True
        else:
            self.is_test = False
            self.is_live_test = False
            self.net_dir_name = None
            self.rival_moves = None

        self.hardware = hw.hardware(angles_num, imgs_if_test)
        self.chesshelper = ch.chess_helper(ch.chess_helper.USER)
        self.delay_chesshelper = ch.chess_helper(ch.chess_helper.USER)
        self.ph_angles = []

        for i in range(angles_num):
            self.ph_angles.append(
                photos_angle_2.photos_angle_2(self.hardware, self.chesshelper,
                                              self.delay_chesshelper, i))

        for ang in self.ph_angles:
            ang.init_colors()

        self.movefinder = fm.find_moves_rank(self.chesshelper,
                                             self.delay_chesshelper,
                                             self.net_dir_name)
        self.chess_engine = chess_engine_wrapper.chess_engine_wrapper()
        self.bad_angles = []
Exemplo n.º 2
0
def tester2(main_im_name, im1_name, im2_name, is_my_turn, loc):
    main_im = scipy.misc.imread(main_im_name)
    im1 = scipy.misc.imread(im1_name)
    im2 = scipy.misc.imread(im2_name)
    if is_my_turn:
        chesshelper = chess_helper.chess_helper(chess_helper.chess_helper.ME)
    else:
        chesshelper = chess_helper.chess_helper(
            chess_helper.chess_helper.RIVAL)
    colorfilter = filter_colors(main_im, chesshelper)
    colorfilter.set_prev_im(im1)
    im1_square = colorfilter.get_square_image(im1, loc)
    im2_square = colorfilter.get_square_image(im2, loc)

    is_white = chesshelper.square_color(loc)

    im1_cat = colorfilter.catalogue_colors(im1_square, is_white)
    im2_cat = colorfilter.catalogue_colors(im2_square, is_white)
    im1_cat_show = colorfilter.catalogue_colors_show(im1_square, is_white)
    im2_cat_show = colorfilter.catalogue_colors_show(im2_square, is_white)

    scipy.misc.imsave('cat1.JPEG', im1_cat_show)
    scipy.misc.imsave('cat2.JPEG', im2_cat_show)
    diff_im = colorfilter.make_binary_relevant_diff_im(im1_cat, im2_cat,
                                                       is_white)
    scipy.misc.imsave('cat_diff.JPEG', diff_im)
    scipy.misc.imsave('im1_square.JPEG', im1_square)
    scipy.misc.imsave('im2_square.JPEG', im2_square)
    square_diff = colorfilter.get_square_diff(im2, loc)
    scipy.misc.imsave('square_diff.JPEG', square_diff)
    return
Exemplo n.º 3
0
def tester(main_im_name, im1_name, im2_name, is_my_turn, loc, is_source):
    main_im = misc.imresize(misc.imread(main_im_name), (600, 600))
    if is_my_turn:
        chesshelper = chess_helper.chess_helper(chess_helper.chess_helper.ME)
    else:
        chesshelper = chess_helper.chess_helper(
            chess_helper.chess_helper.RIVAL)
    colorfilter = filter_colors.filter_colors(main_im, chesshelper)
    im1 = misc.imread(im1_name)
    # im1 = misc.imresize(misc.imread(im1_name), PIXELS)
    colorfilter.set_prev_im(im1)
    #im1_square = colorfilter.get_square_image(im1, loc, is_my_turn)
    im2 = misc.imread(im2_name)
    # im2 = misc.imresize(misc.imread(im2_name), PIXELS)
    #im2_square = colorfilter.get_square_image(im2, loc, is_my_turn)
    #is_white = chesshelper.square_color(loc)
    #main_colors = colorfilter.main_colors
    #me_him_colors = update_colors_show(main_colors)
    #im1_cat_show = catalogue_colors_show(im1_square, is_white, main_colors, me_him_colors)
    #im2_cat_show = catalogue_colors_show(im2_square, is_white, main_colors, me_him_colors)
    # scipy.cv2.imwrite('tester_1.JPEG', im1_square)
    # scipy.cv2.imwrite('tester_2.JPEG', im2_square)
    # scipy.cv2.imwrite('tester_1_cat.JPEG', im1_cat_show)
    # scipy.cv2.imwrite('tester_2_cat.JPEG', im2_cat_show)
    #t_init = time.time()
    square_diff = colorfilter.get_square_diff(im2, loc, is_source)
    #t_final = time.time()
    scipy.cv2.imwrite('test_dir/tester_diff_' + loc + '.jpg', square_diff)
    #tdelta = t_final - t_init
    #print('measured time is: ', round(tdelta, 3), ' sec')
    return
Exemplo n.º 4
0
def main_colors_tester(folder_name):
    chess_helper = chess_helper.chess_helper(True)
    delay_chess_helper = chess_helper.chess_helper(True)
    img_names = os.listdir(folder_name)
    img_array = []
    for j in range(len(img_names)):
        image = cv2.imread(folder_name + '/' + img_names[j], cv2.IMREAD_COLOR)
        filter = filter_colors_2(image, chess_helper, delay_chess_helper)
    return
Exemplo n.º 5
0
def filter_color_tester(im_bef_name, im_aft_name, loc, is_source):
    im_bef = cv2.imread(im_bef_name)
    im_aft = cv2.imread(im_aft_name)
    chess_helper = chess_helper.chess_helper(True)
    delay_chess_helper = chess_helper.chess_helper(True)
    filter = filter_colors_2(im_bef, chess_helper, delay_chess_helper)
    square_diff, befor2save, after2save = filter.get_square_diff(im_aft, loc, is_source)
    scipy.misc.imsave("test_befor.jpg", befor2save)
    scipy.misc.imsave("test_after.jpg", after2save)
    cv2.imwrite("test_diff.jpg", square_diff)
    return
Exemplo n.º 6
0
def tester2_1(main_colors, im1_name, im2_name, is_my_turn, loc, is_source):
    if is_my_turn:
        chesshelper = chess_helper.chess_helper(chess_helper.chess_helper.ME)
    else:
        chesshelper = chess_helper.chess_helper(
            chess_helper.chess_helper.RIVAL)
    colorfilter = filter_colors.filter_colors(im1_name, chesshelper,
                                              main_colors)
    im1 = misc.imresize(misc.imread(im1_name), (PIXELS, PIXELS))
    colorfilter.set_prev_im(im1)
    tester2(im2_name, loc, is_source, colorfilter)
    return
Exemplo n.º 7
0
def get_square_diffs_test(im1, im2, piece_before, piece_below_before,piece_after, piece_below_after, loc, is_source):
    chesshelper = chess_helper.chess_helper()
    filter = filter_colors_2(im1,chesshelper,chesshelper)
    before_square = cv2.resize(filter.get_square_image(im1, loc), PIXELS_SQUARE)
    before_square = fit_colors_test(before_square,piece_before,piece_below_before,filter)
    after_square = cv2.resize(filter.get_square_image(im2, loc), PIXELS_SQUARE)
    after_square = fit_colors_test(after_square,piece_after,piece_below_after,filter)
    square_diff = make_binary_relevant_diff_im_test(filter,before_square, after_square, loc, is_source,piece_before,piece_after,piece_below_before, piece_below_after)
    return square_diff
Exemplo n.º 8
0
 def __init__(self):
     self.hardware = hw.hardware()
     self.boardid = boardid.identify_board()
     board_im = self.hardware.get_image()
     # TODO : get starting player type by color!
     cut_board_im = self.boardid.get_board_image(board_im)
     self.chesshelper = ch.chess_helper(ch.chess_helper.ME)
     self.colorfilter = filter_colors.filter_colors(cut_board_im,
                                                    self.chesshelper)
     self.movefinder = fm.find_move(self.chesshelper)
Exemplo n.º 9
0
def tester(main_im_name, im1_name, im2_name, is_white, is_my_turn):
    main_im = scipy.misc.imread(main_im_name)
    im1 = scipy.misc.imread(im1_name)
    im2 = scipy.misc.imread(im2_name)
    if is_my_turn:
        chesshelper = chess_helper.chess_helper(chess_helper.chess_helper.ME)
    else:
        chesshelper = chess_helper.chess_helper(
            chess_helper.chess_helper.RIVAL)
    colorfilter = filter_colors(main_im, chesshelper)
    im1_cat = colorfilter.catalogue_colors(im1, is_white)
    im2_cat = colorfilter.catalogue_colors(im2, is_white)
    im1_cat_show = colorfilter.catalogue_colors_show(im1, is_white)
    im2_cat_show = colorfilter.catalogue_colors_show(im2, is_white)

    scipy.misc.imsave('cat1.JPEG', im1_cat_show)
    scipy.misc.imsave('cat2.JPEG', im2_cat_show)
    diff_im = colorfilter.make_binary_relevant_diff_im(im1_cat, im2_cat,
                                                       is_white)
    scipy.misc.imsave('cat_diff.JPEG', diff_im)
    return
Exemplo n.º 10
0
def carmels_tester(dir):
    helper = chess_helper.chess_helper(True)
    filter = filter_colors(cv2.imread('second_cut_img1.jpg'), helper)
    img_names = os.listdir(dir)
    prev_img = cv2.imread(dir + '/' + img_names[0])
    for i in range(1, len(img_names)):
        im = cv2.imread(dir + '/' + img_names[i])
        print('im_num' + str(i))
        print(filter.rank_side(prev_img, im, True))
        print(filter.rank_side(prev_img, im, False))


#carmels_tester('crops_0')
Exemplo n.º 11
0
def tester_side(main_im_name, im1_name, im2_name):
    im1 = cv2.imread(im1_name)
    im2 = cv2.imread(im2_name)
    main_im = cv2.imread(main_im_name)
    helper = chess_helper.chess_helper(True)
    filter = filter_colors(main_im, helper)
    right_is_good = filter_colors.does_side_good(filter, im1, im2, True)
    left_is_good = filter_colors.does_side_good(filter, im1, im2, False)
    print('right size is:')
    if right_is_good:
        print('good')
    else:
        print('bad')
    print('left size is:')
    if left_is_good:
        print('good')
    else:
        print('bad')
    return
Exemplo n.º 12
0
    def __init__(self,
                 angles_num,
                 real_moves_if_test=None,
                 imgs_if_test=None,
                 if_save_and_print=True):
        self.if_save_and_print = if_save_and_print
        self.moves_counter = -1
        self.black_im = self.create_black_im()
        if real_moves_if_test is not None:
            self.is_test = True
            self.real_moves = real_moves_if_test

        else:
            self.is_test = False

        self.hardware = hw.hardware(angles_num, imgs_if_test)
        self.my_turn = self.hardware.is_i_first()
        # TODO : get starting player type by color!

        self.chesshelper = ch.chess_helper(ch.chess_helper.ME)

        self.ph_angles = []
        gui_img_manager.set_finished(False)

        for i in range(angles_num):
            gui_img_manager.set_camera(i)
            self.ph_angles.append(
                photos_angle.photos_angle(self.hardware, self.chesshelper, i))
            self.ph_angles[i].prep_img()

        for ang in self.ph_angles:
            ang.init_colors()

        gui_img_manager.set_finished(True)

        self.movefinder = fm.find_moves_rank(self.chesshelper)

        self.chess_engine = chess_engine_wrapper.chess_engine_wrapper()
        self.last_move = None
Exemplo n.º 13
0
def berkos_tester_2(fold_name):
    make_dir("berkos")
    if fold_name in os.listdir("berkos"):
        raise Exception("change the name of tje folder!")
    else:
        make_dir("berkos\\" + fold_name)
    ch = chess_helper.chess_helper(True)
    hw = hardware.hardware(1)
    cnt = 0
    while True:
        cnt += 1
        for i in range(1):
            while True:
                try:
                    ph = photos_angle_2.photos_angle_2(hw, ch, ch, i)
                    ph.prep_img()
                    img = ph.get_new_img()
                    cv2.imwrite("berkos\\" + fold_name + "\\" + str(cnt) +
                                "_" +
                                str(i) + ".jpg", img)
                    break
                except:
                    print("pls take_another_img")
Exemplo n.º 14
0
def test_find_move():
    tester = chess_helper.chess_helper(True)
    move_finder = find_moves_rank(tester)
    img = cv2.imread('f8.jpg')
    img = move_finder.makeoneZero(img)
    print(move_finder.check_square(img))
Exemplo n.º 15
0
def test_find_move():
    tester = chess_helper.chess_helper(True)
    move_finder = find_moves_rank(tester)
    img = cv2.imread('g1_abv.jpg')