diff --git a/src/preprocessor.py b/src/preprocessor.py index e2625bbf12b51116fdc30a007313c3177f533286..ea634b83e189fb51ab28e706c2b3d972ed9865b7 100644 --- a/src/preprocessor.py +++ b/src/preprocessor.py @@ -98,6 +98,7 @@ class Preprocessor: # data augmentation img = img.astype(np.float) if self.data_augmentation: + # photometric data augmentation if random.random() < 0.25: def rand_odd(): @@ -128,13 +129,34 @@ class Preprocessor: target = np.ones(self.img_size[::-1]) * 255 img = cv2.warpAffine(img, M, dsize=self.img_size, dst=target, borderMode=cv2.BORDER_TRANSPARENT) - # photometric data augmentation - if random.random() < 0.5: - img = img * (0.25 + random.random() * 0.75) - if random.random() < 0.25: - img = np.clip(img + (np.random.random(img.shape) - 0.5) * random.randint(1, 25), 0, 255) - if random.random() < 0.1: - img = 255 - img + # # photometric data augmentation + # if random.random() < 0.5: + # img = img * (0.25 + random.random() * 0.75) + # if random.random() < 0.25: + # img = np.clip(img + (np.random.random(img.shape) - 0.5) * random.randint(1, 25), 0, 255) + # if random.random() < 0.1: + # img = 255 - img + + #random line on picture + + + img=img.astype(np.uint8) + img = cv2.blur(img,(3,3)) + img = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\ + cv2.THRESH_BINARY,11,2) + + start_hight =32- random.randint(0, int(32/4)) + end_hight =32- random.randint(0, int(32/4)) + thickness = random.randint(1, 3) + + #draw line on image, starting at 0,start_hight, ending at w, end_hight + cv2.line(img, (0, start_hight), (127, end_hight), (0), thickness) + + # show_img = img.astype(np.uint8) + # cv2.imshow('img', show_img) + # cv2.waitKey(1000) + img = img.astype(np.float) + # no data augmentation else: diff --git a/src/webserver.py b/src/webserver.py index b43ee716414192e99f6f183aea5048b71921a688..7bd016c56ed97b160e399ca7558f1555e6a6b146 100644 --- a/src/webserver.py +++ b/src/webserver.py @@ -18,7 +18,7 @@ csv_path = '../tns.csv' char_list = htr.char_list_from_file() chars = ''.join(char_list) -word_chars = open('../model/wordCharList.txt').read().splitlines()[0] +#word_chars = open('../model/wordCharList.txt').read().splitlines()[0] matrikel_numbers = [] @app.route('/getNames', methods=['GET']) @@ -43,10 +43,7 @@ def predictNach(): model_name.corpus = open('../data/Nachname.txt').read().split()[:200] #check time of infer_batch - start = time.time() recognized, probability = htr_model.Model.infer_batch(model_name, batch) - end = time.time() - print("infer_batch time: ", end-start) processed_image = processed_image + 0.5