def test_generate_supplement_number_ragion(file_name, simple_svm, supplement_svm):
        file_path = os.path.join(data_file_helper.SUPPLEMENT_TRAINING_PATH, file_name)
        the_ragion = Image.load_from_txt(file_path)
        the_number_matrix = numpy.matrix(the_ragion.reshape(1, FULL_SIZE))

        # simple_svm.dag_classify(the_number_matrix).must_equal(
        #     extract_cal_digit(file_path),
        #     failure_msg="simple file path: {0}".format(file_path))

        supplement_svm.dag_classify(the_number_matrix).must_equal(
            extract_real_digit(file_path), failure_msg="supplement file path: {0}".format(file_path)
        )
def generate_standard_supplement_number_ragions(
    ragion_file_path, the_digit, save_path=data_file_helper.SUPPLEMENT_TRAINING_PATH
):
    issue_ragion = Image.load_from_txt(ragion_file_path)
    # os.path.basename(ragion_file_path).pl()
    # ragion_file_path.pl()
    resize_interpolation_arr = (
        (cv2.INTER_AREA, "INTER_AREA"),
        (cv2.INTER_LINEAR, "INTER_LINEAR"),
        (cv2.INTER_CUBIC, "INTER_CUBIC"),
    )

    def resize_and_save_file(interpolation_item):
        interpolation_value, interpolation_name = interpolation_item
        result_file_path = os.path.join(
            save_path, str(the_digit) + "_" + interpolation_name + "_" + os.path.basename(ragion_file_path)
        )
        resized_ragion = main_sudoku.resize_to_cell_size(issue_ragion, interpolation_value)
        Image.save_to_txt(resized_ragion, result_file_path)
        result_file_path.pl()
        return result_file_path

    return map(resize_and_save_file, resize_interpolation_arr)
示例#3
0
    inject(numpy.allclose, 'must_close')

    with test("Ragion.fill"):
        the_ragion = numpy.ones((3,4))
        Ragion.fill(the_ragion, (6,6)).must_close(
            numpy.array(  [[ 0.,  0.,  0.,  0.,  0.,  0.],
                           [ 0.,  1.,  1.,  1.,  1.,  0.],
                           [ 0.,  1.,  1.,  1.,  1.,  0.],
                           [ 0.,  1.,  1.,  1.,  1.,  0.],
                           [ 0.,  0.,  0.,  0.,  0.,  0.],
                           [ 0.,  0.,  0.,  0.,  0.,  0.]]))

    with test(Ragion.review_classified_number_ragion_for_8):
        the_pic_path = '../../resource/test/pic17_no08_real6_cal8.dataset'
        the_ragion = Image.load_from_txt(the_pic_path)
        Ragion.review_classified_number_ragion_for_8(the_ragion, 8).must_equal(6)


        the_pic_path = '../../resource/test/pic16_no05_real8_cal6.dataset'
        the_ragion = Image.load_from_txt(the_pic_path)
        Ragion.review_classified_number_ragion_for_8(the_ragion, 8).must_equal(8)
        # Display.binary_image(the_ragion)
        # save file: ../resource/svm_wrong_digits/pic16_no10_real8_cal6.dataset
        # save file: ../resource/svm_wrong_digits/pic16_no20_real8_cal6.dataset
        pass

    with test("Ragions.fill_to_same_size"):
        ragions = (numpy.ones((3,2)), numpy.ones((2,1)), numpy.ones((2,4)))
        Ragions.fill_to_same_size(ragions).must_close(
            [numpy.array([[ 0.,  1.,  1.,  0.],
示例#4
0
 def generate_number(index):
     file_path = font_training_path+"/"+str(index)+suffix_file_name
     return Image.load_from_txt(file_path)
示例#5
0
import cv2

from picture_sudoku.cv2_helpers.image import Image
from picture_sudoku.cv2_helpers.display import Display

from picture_sudoku.helpers.common import Resource

if __name__ == '__main__':
    from minitest import *

    with test("show freeman"):
        the_pic_path = Resource.get_path('test/pic16_no05_real8_cal6.dataset')
        the_image = Image.load_from_txt(the_pic_path)
        # contours,not_use = cv2.findContours(the_image.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
        # # Display.contours(the_image, contours)
        # contours.ppl()

        cv2.CHAIN_APPROX_NONE.pl()
        cv2.CHAIN_APPROX_SIMPLE.pl()
        contours,not_use = cv2.findContours(the_image.copy(),cv2.RETR_LIST,0)
        # Display.contours(the_image, contours)
        contours.ppl()
示例#6
0
if __name__ == "__main__":
    from minitest import *
    import data_file_helper
    from picture_sudoku.helpers import numpy_helper
    from picture_sudoku.cv2_helpers.display import Display
    from picture_sudoku.cv2_helpers.image import Image
    from picture_sudoku.helpers.common import Resource
    from picture_sudoku import main_sudoku

    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)

    """ how to use training, please see the generator.py"""

    with test(MultipleSvm.dag_classify):
        dataset_matrix_hash = data_file_helper.get_dataset_matrix_hash(data_file_helper.FONT_TRAINING_PATH, (9,))
        mb = MultipleSvm.load_variables(Smo, data_file_helper.FONT_RESULT_PATH)
        mb.dag_classify(dataset_matrix_hash[9][0]).must_equal(9)

    with test("special number"):
        file_name = "sample_18_01_26_resized.dataset"
        issue_ragion = Image.load_from_txt(Resource.get_path("test", file_name))
        transfered_ragion = main_sudoku.transfer_to_digit_matrix(issue_ragion)
        mb = MultipleSvm.load_variables(Smo, data_file_helper.FONT_RESULT_PATH)
        mb.dag_classify(transfered_ragion).must_equal(1)
        # Display.binary_image(main_sudoku.resize_to_cell_size(issue_ragion))
示例#7
0
    final_left = left_x + 1
    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)