Skip to content
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

Make opencv import optional #319

Merged
merged 3 commits into from
Oct 17, 2022
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion xdem/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

import warnings

import cv2 as cv
try:
import cv2 as cv

_has_cv2 = True
except ImportError:
_has_cv2 = False
import numpy as np
import scipy

Expand Down Expand Up @@ -65,6 +70,9 @@ def gaussian_filter_cv(array: NDArrayf, sigma: float) -> NDArrayf:

:returns: the filtered array (same shape as input)
"""
if not _has_cv2:
raise ValueError("Optional dependency needed. Install 'opencv'")

# Check that array dimension is 2, or can be squeezed to 2D
orig_shape = array.shape
if len(orig_shape) == 2:
Expand Down