Commit 4afdba36 authored by myhloli's avatar myhloli
Browse files

perf(table): optimize aspect ratio calculation for text boxes

- Simplify aspect ratio calculation using direct coordinate subtraction
- Remove unnecessary list append operation
- Improve code readability and performance in table rotation detection
parent ac893f32
...@@ -53,20 +53,16 @@ class RapidTableModel(object): ...@@ -53,20 +53,16 @@ class RapidTableModel(object):
# Check if table is rotated by analyzing text box aspect ratios # Check if table is rotated by analyzing text box aspect ratios
is_rotated = False is_rotated = False
if det_res: if det_res:
aspect_ratios = []
vertical_count = 0 vertical_count = 0
for box_ocr_res in det_res: for box_ocr_res in det_res:
p1, p2, p3, p4 = box_ocr_res p1, p2, p3, p4 = box_ocr_res
# Calculate width and height # Calculate width and height
width = max(np.linalg.norm(np.array(p1) - np.array(p2)), width = p3[0] - p1[0]
np.linalg.norm(np.array(p3) - np.array(p4))) height = p3[1] - p1[1]
height = max(np.linalg.norm(np.array(p1) - np.array(p4)),
np.linalg.norm(np.array(p2) - np.array(p3)))
aspect_ratio = width / height if height > 0 else 1.0 aspect_ratio = width / height if height > 0 else 1.0
aspect_ratios.append(aspect_ratio)
# Count vertical vs horizontal text boxes # Count vertical vs horizontal text boxes
if aspect_ratio < 0.8: # Taller than wide - vertical text if aspect_ratio < 0.8: # Taller than wide - vertical text
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment