-
Notifications
You must be signed in to change notification settings - Fork 428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:Alignment during recontruction of image #1657
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,14 +38,18 @@ def synthesize_page( | |
# Draw each word | ||
for block in page["blocks"]: | ||
for line in block["lines"]: | ||
line_ymin = min(int(round(h * word["geometry"][0][1])) for word in line["words"]) | ||
line_ymax = max(int(round(h * word["geometry"][1][1])) for word in line["words"]) | ||
for word in line["words"]: | ||
# Get absolute word geometry | ||
(xmin, ymin), (xmax, ymax) = word["geometry"] | ||
xmin, xmax = int(round(w * xmin)), int(round(w * xmax)) | ||
ymin, ymax = int(round(h * ymin)), int(round(h * ymax)) | ||
|
||
# White drawing context adapted to font size, 0.75 factor to convert pts --> pix | ||
font = get_font(font_family, int(0.75 * (ymax - ymin))) | ||
ymin, ymax = line_ymin, line_ymax | ||
calculate_font_size = int(0.75 * (ymax - ymin)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is interesting. I shall debug this and see why the issue exists There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey there, what models did you use for these? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey :)
|
||
font_size = 0.009 if calculate_font_size <= 0.009 else calculate_font_size | ||
font = get_font(font_family, font_size) | ||
img = Image.new("RGB", (xmax - xmin, ymax - ymin), color=(255, 255, 255)) | ||
d = ImageDraw.Draw(img) | ||
# Draw in black the value of the word | ||
|
@@ -101,7 +105,9 @@ def synthesize_kie_page( | |
ymin, ymax = int(round(h * ymin)), int(round(h * ymax)) | ||
|
||
# White drawing context adapted to font size, 0.75 factor to convert pts --> pix | ||
font = get_font(font_family, int(0.75 * (ymax - ymin))) | ||
calculate_font_size = int(0.75 * (ymax - ymin)) | ||
font_size = 0.009 if calculate_font_size <= 0.009 else calculate_font_size | ||
font = get_font(font_family, font_size) | ||
img = Image.new("RGB", (xmax - xmin, ymax - ymin), color=(255, 255, 255)) | ||
d = ImageDraw.Draw(img) | ||
# Draw in black the value of the word | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest the following:
In this case the user can still decide and adjusting makes only sense if we have lines (so
resolve_lines=True
)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay, I will do that right away