Exemple #1
0
def show_difference(pic_file_path, actual, difference):
    the_image = cv2.imread(pic_file_path, 0)
    the_image = Image.resize_keeping_ratio_by_height(the_image)
    # Display.image(the_image)

    actual_number_indexs, actual_digits, actual_number_ragions = actual
    if difference:
        identified_number_ragions = identify_wrong_number(actual_number_ragions, difference, False)
        # identified_number_ragions = identify_wrong_number(actual_number_ragions, difference)
    else:
        identified_number_ragions = actual_number_ragions
    all_number_ragion = join_number_ragions(actual_number_indexs, identified_number_ragions)
    all_number_ragion = numpy_helper.transfer_values_quickly(all_number_ragion,{1:255})
    # all_number_ragion = Image.colorize(all_number_ragion)
    # Display.image(all_number_ragion)

    if difference:
        wrong_number_ragions = generate_wrong_number_ragions(difference)
        wrong_number_ragion = join_number_ragions(actual_number_indexs, wrong_number_ragions)
        wrong_number_ragion = Image.resize_keeping_ratio_by_height(wrong_number_ragion, all_number_ragion.shape[0])
        wrong_number_ragion = numpy_helper.transfer_values_quickly(wrong_number_ragion,{1:255})

        # Display.image(Ragions.join((all_number_ragion, wrong_number_ragion), 1))
        # Display.ragions([the_image, all_number_ragion, wrong_number_ragion])
        Display.images([Ragions.join((all_number_ragion, wrong_number_ragion),1), the_image])
    else:
        Display.images([all_number_ragion, the_image])
Exemple #2
0
 def binary_ragions(ragions, count_in_row=9, init_value=BLACK):
     '''
         Show the ragions which could have different size.
     '''
     transfered_ragions = [numpy_helper.transfer_values_quickly(ragion,{1:255}) 
         for ragion in ragions]
     Display.ragions(transfered_ragions)
def save_dataset(gray_image, file_name):
    from picture_sudoku.helpers.common import Resource
    file_path = Resource.get_path('test',file_name)
    # file_path = '../../resource/test/' + file_name
    transfered_image = numpy_helper.transfer_values_quickly(gray_image,{255:1})
    print(file_path+" has been saved!")
    return Image.save_to_txt(transfered_image,file_path)
def find_sudoku_number_binary_arr(gray_pic_arr):
    '''
        Find all numbers from a picture in which there is a soduku puzzle.
        The number form is a binary numpy.array in which number parts are 1, 
        the others are 0.
    '''
    '''
        notice: the threshold_value is the key, if it directly impact the binary matrix.
    '''
    threshed_pic_array = cv2_helper.threshold_white_with_mean_percent(gray_pic_arr,0.8)
    cv2_helper.show_pic(threshed_pic_array)

    square = find_max_square(threshed_pic_array)
    # cv2_helper.show_contours_in_pic(threshed_pic_array, [square])

    square_rect=cv2.boundingRect(square)
    number_rects = cv2_helper.Rect.cal_split_ragion_rects(square_rect, 9, 9)
    # cv2_helper.show_rects_in_pic(gray_pic_arr, number_rects)


    binary_pic = numpy_helper.transfer_values_quickly(threshed_pic_array, {BLACK:0, WHITE:1})
    number_binary_ragions = map(lambda c: cv2_helper.get_rect_ragion_with_rect(binary_pic, c),
        number_rects)

    number_binary_ragions = map(remove_border, number_binary_ragions)

    non_empty_indexs, number_binary_ragions = get_nonzero_ragions_and_indexs(number_binary_ragions)
    # indexs.pp()

    # cv2_helper.show_same_size_ragions_as_pic(number_binary_ragions, 9)

    number_binary_ragions = map(remove_margin, number_binary_ragions)

    number_binary_ragions = map(enlarge, number_binary_ragions)
    # cv2_helper.show_pic(threshed_pic_array)
    # cv2_helper.show_same_size_ragions_as_pic(number_binary_ragions, 9)

    return number_binary_ragions, non_empty_indexs
Exemple #5
0
 def binary_rect(the_image, rect):
     Display.rect(numpy_helper.transfer_values_quickly(
         the_image,{1:255}), rect)
Exemple #6
0
 def binary_image(the_image, image_name='image'):        
     Display.image(numpy_helper.transfer_values_quickly(
         the_image,{1:255}))
Exemple #7
0
def show_number_ragions(number_ragions):
    all_number_ragions = Ragions.join_same_size(
            Ragions.fill_to_same_size(number_ragions), 9)
    all_number_ragions = numpy_helper.transfer_values_quickly(all_number_ragions, {1:255})
    Display.image(all_number_ragions)
Exemple #8
0
def save_dataset(gray_image, file_path):
    transfered_image = numpy_helper.transfer_values_quickly(gray_image,{255:1})
    return Image.save_to_txt(transfered_image,file_path)
 def show_number_matrix(number_matrix):
     binary_number_image = number_matrix.reshape((data_file_helper.IMG_SIZE, data_file_helper.IMG_SIZE))
     number_image = numpy_helper.transfer_values_quickly(binary_number_image, {1: 255})
     number_image = numpy.array(number_image, dtype=numpy.uint8)
     # Image.save_to_txt(number_image,'test1.dataset')
     Display.image(number_image)
    final_right = right_x - 1
    return Rect.create(final_left, final_top, final_right, final_bottom)


if __name__ == '__main__':
    from minitest import *
    from picture_sudoku.cv2_helpers.display import Display
    from picture_sudoku.helpers import numpy_helper
    from picture_sudoku.helpers.common import Resource

    inject(numpy.allclose, 'must_close')

    test_image_path = '../../resource/test/'
    image_14_07_path = test_image_path+'sample_14_07.dataset'
    image_14_07 = Image.load_from_txt(image_14_07_path)
    image_14_07_255 = numpy_helper.transfer_values_quickly(image_14_07, {1:255})

    with test(analyze_from_center):
        rect_14_07 = analyze_from_center(image_14_07)
        rect_14_07.must_equal((15, 11, 26, 39))
        # Display.binary_rect(image_14_07, rect_14_07)
        # Image.save_to_txt(Rect.get_ragion(rect_14_07, image_14_07), 
        #     test_image_path+'sample_14_07_no.dataset')

        image_01_03_path = test_image_path+'sample_01_03.dataset'
        image_01_03 = Image.load_from_txt(image_01_03_path)
        rect_01_03 = analyze_from_center(image_01_03)
        rect_01_03.must_equal((27, 26, 12, 17))
        # Display.binary_rect(image_01_03, rect_01_03)

        image_02_null_path = test_image_path+'sample_02_null.dataset'