add support to image stitching for broken images (replace broken part by empty image)
This commit is contained in:
parent
6c54cea57d
commit
7c6f9809bc
@ -3,15 +3,18 @@ from functools import reduce
|
|||||||
from typing import Iterable, Callable, List
|
from typing import Iterable, Callable, List
|
||||||
|
|
||||||
from PIL import Image
|
from PIL import Image
|
||||||
from funcy import juxt, first, rest, rcompose, rpartial, complement, ilen
|
from funcy import juxt, first, rest, rcompose, rpartial
|
||||||
|
|
||||||
from image_prediction.image_extractor.extractor import ImageMetadataPair
|
from image_prediction.image_extractor.extractor import ImageMetadataPair
|
||||||
from image_prediction.info import Info
|
from image_prediction.info import Info
|
||||||
from image_prediction.stitching.grouping import CoordGrouper
|
from image_prediction.stitching.grouping import CoordGrouper
|
||||||
from image_prediction.stitching.split_mapper import HorizontalSplitMapper, VerticalSplitMapper
|
from image_prediction.stitching.split_mapper import HorizontalSplitMapper, VerticalSplitMapper
|
||||||
from image_prediction.stitching.utils import make_coord_getter, flatten_groups_once, validate_box
|
from image_prediction.stitching.utils import make_coord_getter, flatten_groups_once, validate_box
|
||||||
|
from image_prediction.utils import get_logger
|
||||||
from image_prediction.utils.generic import until
|
from image_prediction.utils.generic import until
|
||||||
|
|
||||||
|
logger = get_logger()
|
||||||
|
|
||||||
|
|
||||||
def make_merger_sentinel():
|
def make_merger_sentinel():
|
||||||
def no_new_mergers(pairs):
|
def no_new_mergers(pairs):
|
||||||
@ -184,7 +187,10 @@ def concat_images(im1: Image, im2: Image, metadata: dict, axis):
|
|||||||
|
|
||||||
for im, offset in zip(images, offsets):
|
for im, offset in zip(images, offsets):
|
||||||
box = (offset, 0) if not axis else (0, offset)
|
box = (offset, 0) if not axis else (0, offset)
|
||||||
# TODO: replace image that cannot be opened with white image of same size
|
|
||||||
im_aggr.paste(im, box=box)
|
try: # RED-5170: fails if image is 'broken'
|
||||||
|
im_aggr.paste(im, box=box)
|
||||||
|
except Exception as err:
|
||||||
|
logger.warn(f"{err}: couldn't merge images, replace and passthrough. (page: {metadata[Info.PAGE_IDX]})")
|
||||||
|
|
||||||
return im_aggr
|
return im_aggr
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user