fix: make cv2 dependency optional (#1234)

Makes CV2 dependency optional. It's not used in any of the functional code.
This commit is contained in:
qued 2023-08-29 19:14:00 -05:00 committed by GitHub
parent 5052e6cb3b
commit dde3eb058b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 3 deletions

View File

@ -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

View File

@ -1 +1 @@
__version__ = "0.10.9-dev3"
__version__ = "0.10.9-dev3" # pragma: no cover

View File

@ -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]