def test_data(): """Create NormcapData instance for testing.""" data = NormcapData() data.top = 0 data.bottom = 10 data.left = 0 data.right = 20 data.words = [ { "line_num": 1, "block_num": 1, "par_num": 1, "text": "one" }, { "line_num": 2, "block_num": 1, "par_num": 1, "text": "two" }, { "line_num": 2, "block_num": 1, "par_num": 2, "text": "three" }, { "line_num": 3, "block_num": 1, "par_num": 2, "text": "four" }, ] return data
def test_data(): """Create NormcapData instance for testing.""" data = NormcapData() data.cli_args = { "verbose": True, "mode": "parse", "lang": "eng+deu", "color": "#FF0000", "path": None, } data.test_mode = True data.top = 0 data.bottom = 10 data.left = 0 data.right = 20 data.words = [ {"line_num": 1, "text": "one"}, {"line_num": 2, "text": "two"}, {"line_num": 2, "text": "three"}, {"line_num": 3, "text": "four"}, ] # Space to check trimming test_img_folder = os.path.dirname(os.path.abspath(__file__)) + "/images/" img = Image.open(test_img_folder + "test_email_magic_1.jpg") data.shots = [{"monitor": 0, "image": img}] data.image = img return data
def handle(self, request: NormcapData) -> NormcapData: """Apply OCR on selected image section. Arguments: AbstractHandler {class} -- self request {NormcapData} -- NormCap's session data Returns: NormcapData -- Enriched NormCap's session data """ self._logger.info("Applying OCR...") request.cli_args["lang"] = self.get_language(request.cli_args["lang"]) # Actual OCR & transformation request.words = self.img_to_dict(request.image, request.cli_args["lang"]) self._logger.debug("Dataclass after OCR:%s", request) if self._next_handler: return super().handle(request) return request