Skip to content

Commit

Permalink
Add to_relative_dict method to bbox (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
NastyBoget authored Sep 1, 2023
1 parent 216c68d commit 7497521
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
Changelog
=========

v0.2.3 (2023-09-01)
-------------------
* Add `to_relative_dict` method to `BBox`

v0.2.2 (2023-08-17)
-------------------
* Bugfix in `TesseractDetectorRecognizer`
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.2.2
0.2.3
10 changes: 10 additions & 0 deletions dedocutils/data_structures/bbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ def to_dict(self) -> dict:
res["height"] = self.height
return res

def to_relative_dict(self, page_width: int, page_height: int) -> dict:
res = OrderedDict()
res["x_top_left"] = self.x_top_left / page_width
res["y_top_left"] = self.y_top_left / page_height
res["width"] = self.width / page_width
res["height"] = self.height / page_height
res["page_width"] = page_width
res["page_height"] = page_height
return res

@staticmethod
def from_dict(some_dict: Dict[str, int]) -> "BBox":
return BBox(**some_dict)

0 comments on commit 7497521

Please sign in to comment.