コード例 #1
0
ファイル: lines.py プロジェクト: Vlad-Iliescu/water-meter-ocr
    def process(self, value):
        self.threshold = value
        print(self.threshold)
        detected_edges = ImageProcessor.edges_detection(
            self.processor.base_image, self.low, self.high)
        lines = ImageProcessor.lines_detection(detected_edges, self.threshold)

        with_lines = self.get_line_image(self.processor.original_image, lines)
        cv2.imshow(self.window_name, with_lines)
コード例 #2
0
    def __init__(self, image_path) -> None:
        self.min = config.getint(config.default_section, 'digit_min_height')
        self.max = config.getint(config.default_section, 'digit_max_height')

        self.t1 = config.getint(config.default_section, 'canny_threshold_1')
        self.t2 = config.getint(config.default_section, 'canny_threshold_2')

        self.window_name = "Size"
        self.processor = ImageProcessor(image_path)
        self.processor.fix_skew_angle()
コード例 #3
0
    def process(self):
        detected_edges = ImageProcessor.edges_detection(
            self.processor.base_image, self.t1, self.t2)
        contours = ImageProcessor.contours_detection(detected_edges)

        _, bounding_boxes = ImageProcessor.filter_contours(
            contours, self.min, self.max)
        image = self.get_boxes(self.processor.original_image, bounding_boxes)

        cv2.imshow(self.window_name, image)
コード例 #4
0
class DigitHeight:
    MAX = 300

    def __init__(self, image_path) -> None:
        self.min = config.getint(config.default_section, 'digit_min_height')
        self.max = config.getint(config.default_section, 'digit_max_height')

        self.t1 = config.getint(config.default_section, 'canny_threshold_1')
        self.t2 = config.getint(config.default_section, 'canny_threshold_2')

        self.window_name = "Size"
        self.processor = ImageProcessor(image_path)
        self.processor.fix_skew_angle()

    @staticmethod
    def get_boxes(image, boxes):
        if boxes is None:
            return image

        img = image.copy()
        for box in boxes:
            x, y, w, h = box
            cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2)

        return img

    def process(self):
        detected_edges = ImageProcessor.edges_detection(
            self.processor.base_image, self.t1, self.t2)
        contours = ImageProcessor.contours_detection(detected_edges)

        _, bounding_boxes = ImageProcessor.filter_contours(
            contours, self.min, self.max)
        image = self.get_boxes(self.processor.original_image, bounding_boxes)

        cv2.imshow(self.window_name, image)

    def process_min(self, value):
        self.min = value
        self.process()

    def process_max(self, value):
        self.max = value
        self.process()

    def run(self):
        cv2.namedWindow(self.window_name, cv2.WINDOW_AUTOSIZE)
        cv2.createTrackbar("Low:", self.window_name, self.min, DigitHeight.MAX,
                           lambda x: self.process_min(x))
        cv2.createTrackbar("High:", self.window_name, self.max,
                           DigitHeight.MAX, lambda x: self.process_max(x))
        self.process()
        cv2.waitKey()
コード例 #5
0
ファイル: lines.py プロジェクト: Vlad-Iliescu/water-meter-ocr
 def __init__(self, image_path) -> None:
     self.threshold = config.getint(config.default_section,
                                    'line_threshold')
     self.low = config.getint(config.default_section, 'canny_threshold_1')
     self.high = config.getint(config.default_section, 'canny_threshold_2')
     self.window_name = "Lines"
     self.processor = ImageProcessor(image_path)
コード例 #6
0
from src import ImageProcessor
try:
    from PIL import Image
except ImportError:
    import Image
import pytesseract

if __name__ == '__main__':
    processor = ImageProcessor('wm.jpg')
    # processor._debug = True
    processor.process()
    image = processor.rois_to_image()
    image = ImageProcessor.black_and_white(image)
    img = Image.fromarray(image)
    img.save('rois.png')
    string = pytesseract.image_to_string(img)
    print(string)

    print("Digits Found = {}".format(len(processor.rois)))
    print("OCR = '{}'".format(string))
コード例 #7
0
 def __init__(self, image_path) -> None:
     self.degree = config.getint(config.default_section, 'rotation_deg')
     self.window_name = "Rotation"
     self.processor = ImageProcessor(image_path)
コード例 #8
0
 def process(self, value):
     self.degree = value
     print(self.degree)
     rotated = ImageProcessor.rotate(self.processor.original_image,
                                     self.degree)
     cv2.imshow(self.window_name, rotated)