forked from penny4860/SVHN-deep-digit-detector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_detect.py
45 lines (28 loc) · 1.38 KB
/
3_detect.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#-*- coding: utf-8 -*-
import cv2
import numpy as np
import keras.models
import digit_detector.region_proposal as rp
import digit_detector.show as show
import digit_detector.detect as detector
import digit_detector.file_io as file_io
import digit_detector.preprocess as preproc
import digit_detector.classify as cls
detect_model = "detector_model.hdf5"
recognize_model = "recognize_model.hdf5"
mean_value_for_detector = 107.524
mean_value_for_recognizer = 112.833
model_input_shape = (32,32,1)
DIR = '../datasets/svhn/train'
if __name__ == "__main__":
# 1. image files
img_files = file_io.list_files(directory=DIR, pattern="*.png", recursive_option=False, n_files_to_sample=None, random_order=False)
preproc_for_detector = preproc.GrayImgPreprocessor(mean_value_for_detector)
preproc_for_recognizer = preproc.GrayImgPreprocessor(mean_value_for_recognizer)
char_detector = cls.CnnClassifier(detect_model, preproc_for_detector, model_input_shape)
char_recognizer = cls.CnnClassifier(recognize_model, preproc_for_recognizer, model_input_shape)
digit_spotter = detector.DigitSpotter(char_detector, char_recognizer, rp.MserRegionProposer())
for img_file in img_files[0:]:
# 2. image
img = cv2.imread(img_file)
digit_spotter.run(img, threshold=0.5, do_nms=True, nms_threshold=0.1)