Ejemplo n.º 1
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()
        # square_ragion.mean().ppl()

        threshold_value = Ragion.cal_threshold_value(the_ragion, square_ragion, 0.69)
        thresholded_ragion = Image.threshold_white(the_ragion, threshold_value)
        # thresholded_ragion = cv2.adaptiveThreshold(the_ragion, 255,
        #     cv2.ADAPTIVE_THRESH_MEAN_C,cv2.THRESH_BINARY_INV, blockSize=7, C=2)
        cell_rect = nonzero_rect.analyze_from_center(thresholded_ragion)
        if cell_rect:
            cell_ragion = Rect.get_ragion(cell_rect, thresholded_ragion)
        cell_rect.pl()
        # Display.image(cell_ragion)

        file_path = Resource.get_test_path("sample_19_07_05_image.jpg")
        the_ragion = cv2.imread(file_path, 0)
        # the_ragion.mean().ppl()

        file_path = Resource.get_test_path("sample_19_square.jpg")
        square_ragion = cv2.imread(file_path, 0)
        # square_ragion.mean().ppl()

        threshold_value = Ragion.cal_threshold_value(the_ragion, square_ragion, 0.8)
        thresholded_ragion = Image.threshold_white(the_ragion, threshold_value)
        cell_rect = nonzero_rect.analyze_from_center(thresholded_ragion)
        if cell_rect:
            cell_ragion = Rect.get_ragion(cell_rect, thresholded_ragion)
        number_ragion = numpy_helper.transfer_255to1(cell_ragion)
        number_matrix = main_sudoku.transfer_to_digit_matrix(number_ragion)
        som_svm.dag_classify(number_matrix).pl()
        # thresholded_ragion.ppl()
        # Display.image(thresholded_ragion)