Skip to content

Commit

Permalink
LGVISIUM-102: fixes for bboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
stijnvermeeren-swisstopo committed Nov 11, 2024
1 parent 6c514fa commit cb042bf
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 18 deletions.
20 changes: 8 additions & 12 deletions src/stratigraphy/annotations/draw.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import pandas as pd
from dotenv import load_dotenv
from stratigraphy.data_extractor.data_extractor import FeatureOnPage
from stratigraphy.depthcolumn.depthcolumn import DepthColumn
from stratigraphy.depths_materials_column_pairs.depths_materials_column_pairs import DepthsMaterialsColumnPair
from stratigraphy.depths_materials_column_pairs.bounding_boxes import BoundingBoxes
from stratigraphy.groundwater.groundwater_extraction import Groundwater
from stratigraphy.layer.layer import Layer
from stratigraphy.metadata.coordinate_extraction import Coordinate
Expand Down Expand Up @@ -245,7 +244,7 @@ def draw_material_descriptions(shape: fitz.Shape, derotation_matrix: fitz.Matrix


def draw_depth_columns_and_material_rect(
shape: fitz.Shape, derotation_matrix: fitz.Matrix, depths_materials_column_pairs: list[DepthsMaterialsColumnPair]
shape: fitz.Shape, derotation_matrix: fitz.Matrix, bounding_boxes: list[BoundingBoxes]
):
"""Draw depth columns as well as the material rects on a pdf page.
Expand All @@ -257,25 +256,22 @@ def draw_depth_columns_and_material_rect(
Args:
shape (fitz.Shape): The shape object for drawing.
derotation_matrix (fitz.Matrix): The derotation matrix of the page.
depths_materials_column_pairs (list): List of depth column entries.
bounding_boxes (list[BoundingBoxes]): List of bounding boxes for depth column and material descriptions.
"""
for pair in depths_materials_column_pairs:
depth_column: DepthColumn = pair.depth_column
material_description_rect = pair.material_description_rect

if depth_column: # Draw rectangle for depth columns
for bboxes in bounding_boxes:
if bboxes.depth_column_bbox: # Draw rectangle for depth columns
shape.draw_rect(
fitz.Rect(depth_column.rect()) * derotation_matrix,
fitz.Rect(bboxes.depth_column_bbox.rect) * derotation_matrix,
)
shape.finish(color=fitz.utils.getColor("green"))
for depth_column_entry in depth_column.entries: # Draw rectangle for depth column entries
for depth_column_entry in bboxes.depth_column_entry_bboxes: # Draw rectangle for depth column entries
shape.draw_rect(
fitz.Rect(depth_column_entry.rect) * derotation_matrix,
)
shape.finish(color=fitz.utils.getColor("purple"))

shape.draw_rect( # Draw rectangle for material description column
fitz.Rect(material_description_rect) * derotation_matrix,
bboxes.material_description_bbox.rect * derotation_matrix,
)
shape.finish(color=fitz.utils.getColor("red"))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def to_json(self) -> dict:
"""
return {
"depth_column_rect": self.depth_column_bbox.to_json() if self.depth_column_bbox else None,
"depth_column_entries": [entry.to_json for entry in self.depth_column_entry_bboxes],
"depth_column_entries": [entry.to_json() for entry in self.depth_column_entry_bboxes],
"material_description_rect": self.material_description_bbox.to_json(),
"page": self.page,
}
12 changes: 7 additions & 5 deletions src/stratigraphy/extract.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,13 @@ def process_page(
else:
depth_column_bbox = None
depth_column_entry_bboxes = []
BoundingBoxes(
depth_column_bbox=depth_column_bbox,
depth_column_entry_bboxes=depth_column_entry_bboxes,
material_description_bbox=BoundingBox(pair.material_description_rect),
page=page_number,
bounding_boxes.append(
BoundingBoxes(
depth_column_bbox=depth_column_bbox,
depth_column_entry_bboxes=depth_column_entry_bboxes,
material_description_bbox=BoundingBox(pair.material_description_rect),
page=page_number,
)
)

layer_predictions = [
Expand Down

0 comments on commit cb042bf

Please sign in to comment.