diff --git a/CHANGELOG.md b/CHANGELOG.md index 5d086a3ab..8c7fc459a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ ### Fixes +* Make cv2 dependency optional * Edit `add_pytesseract_bbox_to_elements`'s (`ocr_only` strategy) `metadata.coordinates.points` return type to `Tuple` for consistency. * Re-enable test-ingest-confluence-diff for ingest tests * Fix syntax for ingest test check number of files diff --git a/unstructured/__version__.py b/unstructured/__version__.py index b71dbff24..e65925396 100644 --- a/unstructured/__version__.py +++ b/unstructured/__version__.py @@ -1 +1 @@ -__version__ = "0.10.9-dev3" +__version__ = "0.10.9-dev3" # pragma: no cover diff --git a/unstructured/partition/utils/xycut.py b/unstructured/partition/utils/xycut.py index c95ab2dc6..52b669369 100644 --- a/unstructured/partition/utils/xycut.py +++ b/unstructured/partition/utils/xycut.py @@ -1,8 +1,9 @@ from typing import List -import cv2 import numpy as np +from unstructured.utils import requires_dependencies + """ This module contains the implementation of the XY-Cut sorting approach @@ -157,7 +158,10 @@ def bbox2points(bbox): return [left, top, right, top, right, bottom, left, bottom] +@requires_dependencies("cv2") def vis_polygon(img, points, thickness=2, color=None): + import cv2 + br2bl_color = color tl2tr_color = color tr2br_color = color @@ -196,6 +200,7 @@ def vis_polygon(img, points, thickness=2, color=None): return img +@requires_dependencies("cv2") def vis_points( img: np.ndarray, points, @@ -206,13 +211,15 @@ def vis_points( Args: img: - points: [N, 8] 8: x1,y1,x2,y2,x3,y3,x3,y4 + points: [N, 8] 8: x1,y1,x2,y2,x3,y3,x4,y4 texts: color: Returns: """ + import cv2 + points = np.array(points) assert len(texts) == points.shape[0]