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

import cv2 

import os 

from hutts_utils.hutts_logger import logger 

DESKTOP = os.path.join(os.path.join(os.path.expanduser('~')), 'Desktop') 

 

 

class Pipeline: 

""" 

The Pipeline will perform all necessary processing on the image and is built by the PipelineBuilder. 

""" 

def __init__(self, blur_manager=None, color_manager=None, face_detector=None, threshold_manager=None): 

""" 

Initialize Pipeline with parameters passed from the Builder. 

""" 

self.blur_manager = blur_manager 

self.color_manager = color_manager 

self.face_detector = face_detector 

self.threshold_manager = threshold_manager 

 

def process_text_extraction(self, useIO, image, remove_face=False): 

""" 

This function applies all the processing needed to extract text from a image. 

Author(s): 

Nicolai van Niekerk 

Args: 

useIO (boolean): Whether or not to write images to disk 

image (:obj:'OpenCV image'): Image to which processing should be applied to. 

remove_face :boolean: If the remove face flag is set to true extra processes will 

be activated during the pre-processing phase to remove the face from the image. 

Returns: 

image: The processed image. 

 

""" 

 

# Remove face from image. 

logger.info("Removing face: " + str(remove_face)) 

if remove_face: 

logger.info("REMOVING FACE...") 

image = self.face_detector.blur_face(image) 

if useIO: 

cv2.imwrite(DESKTOP + "/output/4.png", image) 

 

# Blur image. 

logger.info("Blurring image...") 

blur_image = self.blur_manager.apply(image) 

if useIO: 

cv2.imwrite(DESKTOP + "/output/5.png", blur_image) 

 

# Apply channel image_processing, tophat, blackhat or histogram equalization. 

logger.info("Removing color channel...") 

color_image = self.color_manager.apply(blur_image) 

if useIO: 

cv2.imwrite(DESKTOP + "/output/6.png", color_image) 

 

# Convert image to grayscale. 

logger.info("Converting image to grayscale...") 

gray_image = cv2.cvtColor(color_image, cv2.COLOR_BGR2GRAY) 

if useIO: 

cv2.imwrite(DESKTOP + "/output/7.png", gray_image) 

 

# Apply thresholding. 

logger.info("Applying thresholding...") 

thresholded_image = self.threshold_manager.apply(gray_image) 

if useIO: 

cv2.imwrite(DESKTOP + "/output/8.png", thresholded_image) 

 

return thresholded_image 

 

def process_face_extraction(self, image): 

""" 

This function applies all the processing needed to extract a face from a image. 

Author(s): 

Stephan Nell 

Args: 

image (:obj:'OpenCV image'): Image to which processing should be applied to. 

Returns: 

image: The processed image. 

 

""" 

logger.info("Extracting face from image") 

extracted_face = self.face_detector.extract_face(image) 

 

return extracted_face