coordinate transformers refac
This commit is contained in:
parent
bf85ef357c
commit
0376223c9d
@ -4,9 +4,21 @@ import abc
|
||||
class CoordinateTransformer:
|
||||
|
||||
@abc.abstractmethod
|
||||
def forward(self, metadata):
|
||||
def _forward(self, metadata):
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractmethod
|
||||
def backward(self, metadata):
|
||||
def _backward(self, metadata):
|
||||
raise NotImplementedError
|
||||
|
||||
def forward(self, metadata):
|
||||
try:
|
||||
return self._forward(metadata)
|
||||
except TypeError:
|
||||
return map(self._forward, metadata)
|
||||
|
||||
def backward(self, metadata):
|
||||
try:
|
||||
return self._backward(metadata)
|
||||
except TypeError:
|
||||
return map(self._backward, metadata)
|
||||
|
||||
@ -3,9 +3,9 @@ from image_prediction.transformer.transformers.coordinate.coordinate_transformer
|
||||
|
||||
class FitzCoordinateTransformer(CoordinateTransformer):
|
||||
|
||||
def forward(self, metadata: dict):
|
||||
def _forward(self, metadata: dict):
|
||||
"""Fitz uses top left corner as origin; we take this as the reference coordinate system."""
|
||||
return metadata
|
||||
|
||||
def backward(self, metadata: dict):
|
||||
def _backward(self, metadata: dict):
|
||||
return self.forward(metadata)
|
||||
|
||||
@ -3,9 +3,9 @@ from image_prediction.transformer.transformers.coordinate.coordinate_transformer
|
||||
|
||||
class FPDFCoordinateTransformer(CoordinateTransformer):
|
||||
|
||||
def forward(self, metadata: dict):
|
||||
def _forward(self, metadata: dict):
|
||||
"""FPDF uses top left corner as origin; we take this as the reference coordinate system."""
|
||||
return metadata
|
||||
|
||||
def backward(self, metadata: dict):
|
||||
def _backward(self, metadata: dict):
|
||||
return self.forward(metadata)
|
||||
|
||||
@ -8,12 +8,12 @@ from image_prediction.transformer.transformers.coordinate.coordinate_transformer
|
||||
|
||||
class PDFNetCoordinateTransformer(CoordinateTransformer):
|
||||
|
||||
def forward(self, metadata: dict):
|
||||
def _forward(self, metadata: dict):
|
||||
"""PDFNet coordinate system origin is in the bottom left corner."""
|
||||
y1, y2, page_height = itemgetter(Info.Y1, Info.Y2, Info.PAGE_HEIGHT)(metadata)
|
||||
y1_t = page_height - y2
|
||||
y2_t = page_height - y1
|
||||
return {**omit(metadata, [Info.Y1, Info.Y2]), **{Info.Y1: y1_t, Info.Y2: y2_t}}
|
||||
|
||||
def backward(self, metadata: dict):
|
||||
def _backward(self, metadata: dict):
|
||||
return self.forward(metadata)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user