Fix importing of opencv when libraries are not installed / extensions are not compiled.

This commit is contained in:
Stefan van der Walt
2009-10-17 07:37:29 +02:00
parent 62f67611af
commit 8ec3abb3f5
6 changed files with 6028 additions and 4869 deletions
+20 -5
View File
@@ -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."
+2 -3
View File
@@ -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):
File diff suppressed because it is too large Load Diff
+10
View File
@@ -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()
File diff suppressed because it is too large Load Diff
+9
View File
@@ -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