Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

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

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

import os 

from image_preprocessing.blur_manager import BlurManager 

from image_preprocessing.color_manager import ColorManager 

from image_preprocessing.face_manager import FaceDetector 

from image_preprocessing.pipeline_builder import PipelineBuilder 

from image_preprocessing.thresholding_manager import ThresholdingManager 

from hutts_utils.hutts_logger import logger 

from hutts_utils.pypath import correct_path 

 

# Constants path to trained data for Shape Predictor. 

SHAPE_PREDICTOR_PATH = correct_path("{base_path}/trained_data/shape_predictor_face_landmarks.dat".format( 

base_path=os.path.abspath(os.path.dirname(__file__)))) 

 

 

class BuildDirector: 

""" 

The BuildDirector constructs the Pipeline using the PipelineBuilder 

""" 

@staticmethod 

def construct_text_extract_pipeline(preferences, identification_type): 

""" 

This function constructs the pipeline for text extraction. 

This includes building different managers with their specific parameters. 

These managers will be called within the pipeline when executed. 

Author(s): 

Nicolai van Niekerk and Marno Hermann 

Args: 

preferences (dict): User-specified techniques to use in pipeline. 

identification_type (string): Contains the type of identification, this is used 

to determine which techniques are used. 

Returns: 

:Pipeline (Constructed pipeline) 

""" 

builder = PipelineBuilder() 

# Use template matching to identify type here 

 

if 'blur_method' in preferences: 

blur_method = preferences['blur_method'] 

elif identification_type == 'idcard': 

blur_method = 'gaussian' 

elif identification_type == 'idbook': 

blur_method = 'gaussian' 

elif identification_type == 'studentcard': 

blur_method = 'median' 

else: 

# Default 

blur_method = 'median' 

 

if blur_method == 'median': 

blur_kernel_size = [3] 

else: 

if identification_type == 'idbook': 

blur_kernel_size = [(3, 3)] 

elif identification_type == 'idcard': 

blur_kernel_size = [(3, 3)] 

else: 

blur_kernel_size = [(3, 3)] 

 

if 'threshold_method' in preferences: 

threshold_method = preferences['threshold_method'] 

elif identification_type == 'idcard': 

threshold_method = 'adaptive' 

elif identification_type == 'idbook': 

threshold_method = 'adaptive' 

elif identification_type == 'studentcard': 

threshold_method = 'adaptive' 

else: 

# Default 

threshold_method = 'adaptive' 

 

if 'color' in preferences: 

color_extraction_type = 'extract' 

color = preferences['color'] 

elif identification_type == 'idcard': 

color_extraction_type = 'extract' 

color = 'red_blue' 

elif identification_type == 'idbook': 

color_extraction_type = 'extract' 

color = 'red_blue' 

elif identification_type == 'studentcard': 

color_extraction_type = 'extract' 

color = 'red' 

else: 

# Default 

color_extraction_type = 'extract' 

color = 'red' 

 

logger.debug("Blur Method: " + blur_method) 

logger.debug("Kernel Size: " + str(blur_kernel_size)) 

logger.debug("ColorXType: " + color_extraction_type) 

logger.debug("Color: " + color) 

logger.debug("Threshold Method: " + threshold_method) 

 

blur_manager = BlurManager(blur_method, blur_kernel_size) 

color_manager = ColorManager(color_extraction_type, color) 

threshold_manager = ThresholdingManager(threshold_method) 

face_detector = FaceDetector(SHAPE_PREDICTOR_PATH) 

 

builder.set_blur_manager(blur_manager) 

builder.set_color_manager(color_manager) 

builder.set_face_detector(face_detector) 

builder.set_threshold_manager(threshold_manager) 

 

return builder.get_result() 

 

@staticmethod 

def construct_face_extract_pipeline(): 

""" 

This function constructs the pipeline for face extraction. 

This includes building different managers with their specific parameters. 

These managers will be called within the pipeline when executed. 

Author(s): 

Stephan Nell 

Returns: 

:Pipeline (Constructed pipeline) 

""" 

logger.debug("Shape Predictor path: " + SHAPE_PREDICTOR_PATH) 

builder = PipelineBuilder() 

 

face_detector = FaceDetector(SHAPE_PREDICTOR_PATH) 

builder.set_face_detector(face_detector) 

 

return builder.get_result()