mirror of
https://github.com/wassname/scikit-image.git
synced 2026-08-19 12:40:22 +08:00
Fix importing of opencv when libraries are not installed / extensions are not compiled.
This commit is contained in:
@@ -1,9 +1,24 @@
|
||||
import ctypes
|
||||
import sys
|
||||
|
||||
# try to open the opencv libs
|
||||
# prints a warning if the libs are not found
|
||||
from _libimport import cv, cxcore
|
||||
|
||||
from opencv_constants import *
|
||||
from opencv_cv import *
|
||||
|
||||
# Note: users should be able to import this module even if
|
||||
# the extensions are uncompiled or the opencv libraries unavailable.
|
||||
# In that case, the opencv functionality is simply unavailable.
|
||||
|
||||
cv = None
|
||||
cxcore = None
|
||||
try:
|
||||
from opencv_cv import *
|
||||
except ImportError:
|
||||
print """*** The opencv extension was not compiled. Run
|
||||
|
||||
python setup.py build_ext -i
|
||||
|
||||
in the source directory to build in-place. Please refer to INSTALL.txt
|
||||
for further detail."""
|
||||
|
||||
except RuntimeError:
|
||||
# Libraries could not be loaded
|
||||
print "*** Skipping import of OpenCV functions."
|
||||
|
||||
@@ -16,7 +16,7 @@ import ctypes
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
def _import_opencv_lib(which = "cv"):
|
||||
def _import_opencv_lib(which="cv"):
|
||||
"""
|
||||
Try to import a shared library of OpenCV.
|
||||
|
||||
@@ -32,8 +32,7 @@ def _import_opencv_lib(which = "cv"):
|
||||
if shared_lib is None:
|
||||
warnings.warn(RuntimeWarning(
|
||||
'The opencv libraries were not found. Please ensure that they '
|
||||
'are installed and available on the system path. '
|
||||
'*** Skipping import of OpenCV functions.'))
|
||||
'are installed and available on the system path. '))
|
||||
return shared_lib
|
||||
|
||||
def _tryload_macosx(which):
|
||||
|
||||
+1986
-1405
File diff suppressed because it is too large
Load Diff
@@ -4,7 +4,17 @@ cimport numpy as np
|
||||
from python cimport *
|
||||
from opencv_constants import *
|
||||
from opencv_type cimport *
|
||||
|
||||
# Without the opencv libraries, this extension module cannot function,
|
||||
# so we raise an exception if loading fails.
|
||||
#
|
||||
# Note, however, that users should be able to import scikits.image.opencv
|
||||
# itself without having any of the libraries installed
|
||||
# (the opencv functionality is then simply not available)
|
||||
#
|
||||
from _libimport import cxcore
|
||||
if cxcore is None:
|
||||
raise RuntimeError('Could not load OpenCV libraries.')
|
||||
|
||||
|
||||
np.import_array()
|
||||
|
||||
+4001
-3456
File diff suppressed because it is too large
Load Diff
@@ -11,7 +11,16 @@ from opencv_constants import *
|
||||
from opencv_constants import *
|
||||
from opencv_cv import *
|
||||
|
||||
# Without the opencv libraries, this extension module cannot function,
|
||||
# so we raise an exception if loading fails.
|
||||
#
|
||||
# Note, however, that users should be able to import scikits.image.opencv
|
||||
# itself without having any of the libraries installed
|
||||
# (the opencv functionality is then simply not available)
|
||||
#
|
||||
from _libimport import cv
|
||||
if cv is None:
|
||||
raise RuntimeError('Could not load OpenCV libraries.')
|
||||
|
||||
###################################
|
||||
# opencv function declarations
|
||||
|
||||
Reference in New Issue
Block a user