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)
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
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 '''
def main(): contour = numpy.load(Resource.get_path("test/max_contour_with_noises.npy")) extract_square_from_contour(contour)
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()
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))