Пример #1
0
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)
Пример #2
0
 def test_the_sample(sample_index):
     pic_filepath = Resource.get_path('example_pics/sample'+
         str(sample_index).zfill(2)+'.dataset.jpg')
     # pic_filepath = '../resource/example_pics/sample01.dataset.jpg'    
     result = requests.post(IMAGE_RESULT_URL,
         files={'files':open(pic_filepath,'rb')})
     answer_result = json.loads(result.content)
     return answer_result
Пример #3
0
import numpy
import os
from picture_sudoku.helpers.common import Resource, OtherResource

IMG_SIZE = 32
FULL_SIZE = 1024


FONT_TRAINING_PATH = OtherResource.get_path('font_training')
FONT_RESULT_PATH = OtherResource.get_path('font_training_result')

SUPPLEMENT_RESULT_PATH = OtherResource.get_path('font_supplement_result')

HAND_TRAINING_PATH = OtherResource.get_path('hand_training')
HAND_TESTING_PATH = OtherResource.get_path('hand_testing')
HAND_RESULT_PATH = Resource.get_path('hand_training_result')

SUPPLEMENT_TRAINING_PATH = OtherResource.get_path('supplement_training')

def get_dataset_matrix_hash(the_path, start_with_numbers):
    '''
        main method
    '''
    return {i:numpy.mat(get_dataset_from_filenames(the_path, 
        filter_filenames_with_nums(the_path,(i,)))) for i in start_with_numbers}

def get_dataset_matrix_hash_with_supplement(
        the_path, supplement_path, start_with_numbers):
    '''
        main method
    '''
    #     # 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)
        cell_rect = nonzero_rect.analyze_from_center(thresholded_ragion)
def main():
    contour = numpy.load(Resource.get_path("test/max_contour_with_noises.npy"))
    extract_square_from_contour(contour)
Пример #6
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()
Пример #7
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))