Пример #1
0
 def intent_func():
     global global_smo_svm
     if global_smo_svm==None:
         # global_smo_svm.ppl()
         logger.info("The path of training result: {0}".format(RESULT_PATH))
         global_smo_svm = MultipleSvm.load_variables(Smo, RESULT_PATH)
     number_indexs, digits = get_digits(pic_file_path, global_smo_svm)
     return main_answer.answer_quiz_with_indexs_and_digits(number_indexs, digits)
Пример #2
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()
Пример #3
0
def vertify_all_pics():
    pic_data = gen_pic_test_data()

    # hand_result_path = '../resource/digit_recognition/hand_dataset'
    smo_svm = MultipleSvm.load_variables(Smo, RESULT_PATH)

    def handle_one(i, extend_name='jpg'):
        pic_file_path = '../resource/example_pics/sample'+str(i).zfill(2)+'.dataset.'+extend_name
        actual = main_sudoku.get_digits(pic_file_path, smo_svm, True)
        difference = print_and_get_difference(actual, pic_data[i], i)
        show_difference(pic_file_path, actual, difference)
        return True

    # handle_one(1) 8 ,15
    # map(handle_one, range(1,19))
    # handle_one(90, 'png')

    # handle_one(19)
    handle_one(15)
    #     main_sudoku.answer_quiz_with_pic(image_path).pl()
    #     # gray_image = cv2.imread(image_path, 0)
    #     # Display.image(gray_image)
    #     # /Users/colin/work/picture_sudoku/other_resource/font_training_result

    # with test("for having more than two border lines"):
    #     # image_path = Resource.get_path('example_pics/sample11.dataset.jpg')
    #     # image_path = Resource.get_path('example_pics/sample08.dataset.jpg')
    #     # image_path = Resource.get_path('example_pics/sample16.dataset.jpg')
    #     image_path = Resource.get_path('for_issues/cannot_recognize.jpg')
    #     main_sudoku.answer_quiz_with_pic(image_path).pl()
    #     # gray_image = cv2.imread(image_path, 0)
    #     # Display.image(gray_image)

    with test("get clear number ragion"):
        som_svm = MultipleSvm.load_variables(Smo, data_file_helper.SUPPLEMENT_RESULT_PATH)
        file_path = Resource.get_test_path("sample_15_null_38_image.jpg")
        the_ragion = cv2.imread(file_path, 0)
        # the_ragion.mean().ppl()
        # the_ragion.ppl()
        # thresholded_ragion = Image.threshold_white_with_mean_percent(the_ragion, 0.8)
        # thresholded_ragion.ppl()
        # Display.image(thresholded_ragion)
        file_path = Resource.get_test_path("sample_15_square.jpg")
        square_ragion = cv2.imread(file_path, 0)
        # 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)