Julius Unverfehrt f37b6d7d8e Pull request #13: Add pdf coord conversion
Merge in RR/cv-analysis from add-pdf-coord-conversion to master

Squashed commit of the following:

commit f56b7b45feb78142b032ef0faae2ca8dd020e6c5
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Thu Jul 7 11:26:46 2022 +0200

    update pyinfra

commit 9086ef0a2059688fb8dd5559cda831bbbd36362b
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Thu Jul 7 11:21:53 2022 +0200

    update inpout metadata keys

commit 55f147a5848e22ea62242ea883a0ce53ef1c04a5
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Thu Jul 7 09:16:16 2022 +0200

    update to new input metadata signature

commit df4652fb027f734f2613e4adb7bc5b17edee62e9
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Wed Jul 6 16:55:36 2022 +0200

    refactor

commit e52c674085a9c7411c55a2e0993aa34622284317
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Wed Jul 6 16:15:21 2022 +0200

    update build script, refactor

commit 1f874aea591f25544aaa3f39a4e38fa50a24615e
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Tue Jul 5 17:01:15 2022 +0200

    add rotation formatter

commit b78a69741287a4cd38a90ace98f67e8f1b803737
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Tue Jul 5 09:26:27 2022 +0200

    refactor

commit b3155b8e072530f99114f3ee9135e73afc8f85cb
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Fri Jul 1 15:06:45 2022 +0200

    made assertion robust to floating point precision

commit 4169102a6b5053500a3db2d789d265c2c77d56a4
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Fri Jul 1 15:06:01 2022 +0200

    improve banner

commit dea74593d925c802489e5400297b48a9729038f0
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Fri Jul 1 14:28:08 2022 +0200

    introduce derotation logic for rectangles from rotated pdfs, introduce continious option for coordinates in Rectangle class

commit d07e1dc2731ea7ae9887cc02bb98155bf1565a0d
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Fri Jul 1 10:39:38 2022 +0200

    introduce table parsing formatter to convert pixel values to inches

commit 67ff6730dd7073a0fc9e9698904325dea9537c5b
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Fri Jul 1 08:06:42 2022 +0200

    fixed duplicate logging

commit 6c025409415329028f697bb99986cd0912c7ed54
Author: Julius Unverfehrt <julius.unverfehrt@iqser.com>
Date:   Thu Jun 30 17:10:32 2022 +0200

    add pyinfra mock script
2022-07-07 11:35:12 +02:00

66 lines
2.1 KiB
Python

from json import dumps
import numpy as np
from funcy import identity
class Rectangle:
def __init__(self, x1=None, y1=None, w=None, h=None, x2=None, y2=None, indent=4, format="xywh", discrete=True):
make_discrete = int if discrete else identity
try:
self.x1 = make_discrete(x1)
self.y1 = make_discrete(y1)
self.w = make_discrete(w) if w else make_discrete(x2 - x1)
self.h = make_discrete(h) if h else make_discrete(y2 - y1)
self.x2 = make_discrete(x2) if x2 else self.x1 + self.w
self.y2 = make_discrete(y2) if y2 else self.y1 + self.h
assert np.isclose(self.x1 + self.w, self.x2)
assert np.isclose(self.y1 + self.h, self.y2)
self.indent = indent
self.format = format
except Exception as err:
raise Exception("x1, y1, (w|x2), and (h|y2) must be defined.") from err
def json_xywh(self):
return {"x": self.x1, "y": self.y1, "width": self.w, "height": self.h}
def json_xyxy(self):
return {"x1": self.x1, "y1": self.y1, "x2": self.x2, "y2": self.y2}
def json_full(self):
return {"x1": self.x1, "y1": self.y1, "x2": self.x2, "y2": self.y2, "width": self.w, "height": self.h}
def json(self):
json_func = {"xywh": self.json_xywh, "xyxy": self.json_xyxy}.get(self.format, self.json_full)
return json_func()
def xyxy(self):
return self.x1, self.y1, self.x2, self.y2
def xywh(self):
return self.x1, self.y1, self.w, self.h
@classmethod
def from_xyxy(cls, xyxy_tuple, discrete=True):
x1, y1, x2, y2 = xyxy_tuple
return cls(x1=x1, y1=y1, x2=x2, y2=y2, discrete=discrete)
@classmethod
def from_xywh(cls, xywh_tuple, discrete=True):
x, y, w, h = xywh_tuple
return cls(x1=x, y1=y, w=w, h=h, discrete=discrete)
def __str__(self):
return dumps(self.json(), indent=self.indent)
def __repr__(self):
return str(self.json())
def __iter__(self):
return list(self.json().values()).__iter__()
class Contour:
def __init__(self):
pass