36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
import abc
|
|
|
|
from image_prediction.image_extractor.extractor import ImageMetadataPair
|
|
from image_prediction.info import Info
|
|
|
|
from image_prediction.transformer.transformer import Transformer
|
|
from pdf2img.default_objects.image import ImagePlus
|
|
|
|
|
|
class Formatter(Transformer):
|
|
@abc.abstractmethod
|
|
def format(self, obj):
|
|
raise NotImplementedError
|
|
|
|
def transform(self, obj):
|
|
raise NotImplementedError()
|
|
|
|
def __call__(self, obj):
|
|
return self.format(obj)
|
|
|
|
|
|
def format_image_plus(image: ImagePlus) -> ImageMetadataPair:
|
|
enum_metadata = {
|
|
Info.PAGE_WIDTH: image.info.pageInfo.pageWidth,
|
|
Info.PAGE_HEIGHT: image.info.pageInfo.pageHeight,
|
|
Info.PAGE_IDX: image.info.pageInfo.pageNumber,
|
|
Info.ALPHA: image.info.alpha,
|
|
Info.WIDTH: image.info.boundingBox.width,
|
|
Info.HEIGHT: image.info.boundingBox.height,
|
|
Info.X1: image.info.boundingBox.x0,
|
|
Info.X2: image.info.boundingBox.x1,
|
|
Info.Y1: image.info.boundingBox.y0,
|
|
Info.Y2: image.info.boundingBox.y1,
|
|
}
|
|
return ImageMetadataPair(image.aspil(), enum_metadata)
|