示例#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])
def show_all(square_ragion, index_and_number_ragions):
    '''
        just for test
    '''
    all_number_ragion = []
    for index, number_ragion in index_and_number_ragions:
        ragion_index = len(all_number_ragion)
        if ragion_index < index:
            all_number_ragion += [numpy.zeros((1,1)) for i in range(index-ragion_index)]            
        all_number_ragion.append(number_ragion)
    all_number_ragion = Ragions.join_same_size(
        Ragions.fill_to_same_size(all_number_ragion), 9)
    from picture_sudoku.cv2_helpers.display import Display
    Display.ragions([square_ragion, all_number_ragion])
示例#3
0
def digit_recognize():
    mb = MultipleSvm.load_variables(Smo, RESULT_PATH)

    # file_path = '../resource/svm_wrong_digits/pic04_no17_real8_cal3.dataset'
    file_path = '../resource/svm_wrong_digits/pic04_no33_real8_cal3.dataset'
    # file_path = '../resource/svm_wrong_digits/pic15_no19_real5_cal6_1.dataset'
    # file_path = '../resource/svm_wrong_digits/pic15_no19_real5_cal6.dataset'
    number_ragion = numpy.mat(Image.read_from_number_file(file_path))
    transfered_ragion = numpy_helper.transfer_1to255(number_ragion)
    # adjusted_ragion = main_sudoku.adjust_number_ragion(transfered_ragion)
    adjusted_ragion = adjust_number_ragion2(transfered_ragion)
    # adjusted_ragion = transfered_ragion
    Display.ragions([transfered_ragion, adjusted_ragion])
    adjusted_ragion = numpy_helper.transfer_255to1(adjusted_ragion)
    number_matrix = main_sudoku.transfer_to_digit_matrix(adjusted_ragion)
    mb.dag_classify(number_matrix).ppl()
def extract_square_from_contour(contour):
    the_image = Image.generate_mask(Contour.get_shape(contour))
    # Display.contours(the_image, [contour])
    cv2.drawContours(the_image, [contour], -1, 255, 1)
    # Display.image(the_image)
    # lines = PolarLines.find_suitable_lines(the_image)
    square_ragion = the_image
    vertical_lines = find_vertical_lines(square_ragion)
    border_line_count = 2
    if len(vertical_lines) > border_line_count:
        raise SudokuError("The count of vertical border lines is larger than {0}".format(border_line_count))

    horizontal_lines = find_horizontal_lines(square_ragion)
    if len(horizontal_lines) > border_line_count:
        raise SudokuError("The count of horizontal border lines is larger than {0}".format(border_line_count))
    Display.polar_lines(square_ragion, vertical_lines + horizontal_lines)
    # Display.polar_lines(square_ragion, horizontal_lines)

    intersections = main_analyzer.find_intersections(vertical_lines, horizontal_lines)
    # intersections.ppl()
    Points.to_contour(intersections).ppl()
示例#5
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)
示例#6
0
 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)