mirror of
https://github.com/mikegerber/ocrd_calamari.git
synced 2025-06-08 19:29:53 +02:00
recognize: skip tiny or bin-empty lines, too
This commit is contained in:
parent
395e43c074
commit
8c2e4ca76d
1 changed files with 11 additions and 3 deletions
|
@ -97,14 +97,22 @@ class CalamariRecognize(Processor):
|
||||||
log.debug("Recognizing line '%s' in region '%s'", line.id, region.id)
|
log.debug("Recognizing line '%s' in region '%s'", line.id, region.id)
|
||||||
|
|
||||||
line_image, line_coords = self.workspace.image_from_segment(line, region_image, region_coords, feature_selector=self.features)
|
line_image, line_coords = self.workspace.image_from_segment(line, region_image, region_coords, feature_selector=self.features)
|
||||||
if ('binarized' not in line_coords['features'] and 'grayscale_normalized' not in line_coords['features'] and self.network_input_channels == 1):
|
if ('binarized' not in line_coords['features'] and
|
||||||
|
'grayscale_normalized' not in line_coords['features'] and
|
||||||
|
self.network_input_channels == 1):
|
||||||
# We cannot use a feature selector for this since we don't
|
# We cannot use a feature selector for this since we don't
|
||||||
# know whether the model expects (has been trained on)
|
# know whether the model expects (has been trained on)
|
||||||
# binarized or grayscale images; but raw images are likely
|
# binarized or grayscale images; but raw images are likely
|
||||||
# always inadequate:
|
# always inadequate:
|
||||||
log.warning("Using raw image for line '%s' in region '%s'", line.id, region.id)
|
log.warning("Using raw image for line '%s' in region '%s'", line.id, region.id)
|
||||||
|
|
||||||
line_image = line_image if all(line_image.size) else [[0]]
|
if (not all(line_image.size) or
|
||||||
|
line_image.height <= 8 or line_image.width <= 8 or
|
||||||
|
'binarized' in line_coords['features'] and line_image.convert('1').getextrema()[0] == 255):
|
||||||
|
# empty size or too tiny or no foreground at all: skip
|
||||||
|
log.warning("Skipping empty line '%s' in region '%s'", line.id, region.id)
|
||||||
|
line_image_np = np.array([[0]], dtype=np.uint8)
|
||||||
|
else:
|
||||||
line_image_np = np.array(line_image, dtype=np.uint8)
|
line_image_np = np.array(line_image, dtype=np.uint8)
|
||||||
line_images_np.append(line_image_np)
|
line_images_np.append(line_image_np)
|
||||||
line_coordss.append(line_coords)
|
line_coordss.append(line_coords)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue