File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1010
1111from typing import Literal
1212
13- import cv2
1413import numpy as np
1514import scipy .ndimage as spi
1615import scipy .spatial as spt
@@ -720,6 +719,14 @@ def find_blobs_opencv(
720719 Returns:
721720 Coordinates of blobs
722721 """
722+
723+ # Note:
724+ # Importing OpenCV inside the function in order to eventually raise an ImportError
725+ # when the function is called and OpenCV is not installed. This error will be
726+ # handled by DataLab and the user will be informed that OpenCV is required to use
727+ # this function.
728+ import cv2 # pylint: disable=import-outside-toplevel
729+
723730 params = cv2 .SimpleBlobDetector_Params ()
724731 if min_threshold is not None :
725732 params .minThreshold = min_threshold
Original file line number Diff line number Diff line change 1010
1111import os
1212
13- import cv2
1413import guidata
1514import h5py
1615import numpy
@@ -47,9 +46,14 @@ def pytest_report_header(config): # pylint: disable=unused-argument
4746 f"PythonQwt { qwt .__version__ } , "
4847 f"{ qtpy .API_NAME } { qtbindings_version } [Qt version: { qtpy .QT_VERSION } ]" ,
4948 f"NumPy { numpy .__version__ } , SciPy { scipy .__version__ } , "
50- f"h5py { h5py .__version__ } , "
51- f"scikit-image { skimage .__version__ } , OpenCV { cv2 .__version__ } " ,
49+ f"h5py { h5py .__version__ } , scikit-image { skimage .__version__ } " ,
5250 ]
51+ try :
52+ import cv2 # pylint: disable=import-outside-toplevel
53+
54+ infolist .append (f", OpenCV { cv2 .__version__ } " )
55+ except ImportError :
56+ pass
5357 for vname in ("CDL_DATA" , "PYTHONPATH" , "DEBUG" ):
5458 value = os .environ .get (vname , "" )
5559 if value :
Original file line number Diff line number Diff line change @@ -44,7 +44,6 @@ dependencies = [
4444 " NumPy >= 1.21" ,
4545 " SciPy >= 1.7" ,
4646 " scikit-image >= 0.18" ,
47- " opencv-python-headless >= 4.5" ,
4847 " pandas >= 1.3" ,
4948 " PyWavelets >= 1.1" ,
5049 " psutil >= 5.5" ,
@@ -65,6 +64,7 @@ cdl-tests = "cdl.tests:run"
6564
6665[project .optional-dependencies ]
6766qt = [" PyQt5" ]
67+ opencv = [" opencv-python-headless >= 4.5" ]
6868dev = [" ruff" , " pylint" , " Coverage" , " pyinstaller>=6.0" ]
6969doc = [
7070 " PyQt5" ,
You can’t perform that action at this time.
0 commit comments