Skip to content

Commit 7497521

Browse files
authored
Add to_relative_dict method to bbox (#7)
1 parent 216c68d commit 7497521

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
Changelog
22
=========
3+
4+
v0.2.3 (2023-09-01)
5+
-------------------
6+
* Add `to_relative_dict` method to `BBox`
7+
38
v0.2.2 (2023-08-17)
49
-------------------
510
* Bugfix in `TesseractDetectorRecognizer`

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.2.2
1+
0.2.3

dedocutils/data_structures/bbox.py

+10
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,16 @@ def to_dict(self) -> dict:
7070
res["height"] = self.height
7171
return res
7272

73+
def to_relative_dict(self, page_width: int, page_height: int) -> dict:
74+
res = OrderedDict()
75+
res["x_top_left"] = self.x_top_left / page_width
76+
res["y_top_left"] = self.y_top_left / page_height
77+
res["width"] = self.width / page_width
78+
res["height"] = self.height / page_height
79+
res["page_width"] = page_width
80+
res["page_height"] = page_height
81+
return res
82+
7383
@staticmethod
7484
def from_dict(some_dict: Dict[str, int]) -> "BBox":
7585
return BBox(**some_dict)

0 commit comments

Comments
 (0)