mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-05 15:35:55 +08:00
Allow unit tests to be run when OpenCV is not available.
This commit is contained in:
@@ -1,22 +1,15 @@
|
||||
import ctypes
|
||||
|
||||
# try to open the opencv libs
|
||||
# raise an exception if the libs are not found
|
||||
|
||||
# linux
|
||||
try:
|
||||
ctypes.CDLL('libcv.so')
|
||||
except:
|
||||
# windows
|
||||
try:
|
||||
ctypes.CDLL('cv.dll')
|
||||
except:
|
||||
raise RuntimeError('The opencv libraries were not found. Please make sure they are installed and available on the system path.')
|
||||
import warnings
|
||||
|
||||
from opencv_constants import *
|
||||
from opencv_cv import *
|
||||
|
||||
#def test(level=1, verbosity=1):
|
||||
# from numpy.testing import Tester
|
||||
# return Tester().test(level, verbosity)
|
||||
libs_found = True
|
||||
|
||||
try:
|
||||
from opencv_cv import *
|
||||
except:
|
||||
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.'))
|
||||
libs_found = False
|
||||
|
||||
@@ -11,14 +11,8 @@ from opencv_constants import *
|
||||
#one of these should work if the user imported the package properly
|
||||
try:
|
||||
cv = ctypes.CDLL('libcv.so')
|
||||
except:
|
||||
try:
|
||||
cv = ctypes.CDLL('cv.dll')
|
||||
except:
|
||||
raise RuntimeError('The opencv libraries were not found. '
|
||||
'Please make sure they are installed and '
|
||||
'available on the system path.')
|
||||
|
||||
except OSError:
|
||||
cv = ctypes.CDLL('cv.dll')
|
||||
|
||||
###################################
|
||||
# opencv function declarations
|
||||
|
||||
@@ -1,77 +1,74 @@
|
||||
# test for the opencv_cv extension module
|
||||
import os
|
||||
import warnings
|
||||
|
||||
import numpy as np
|
||||
from numpy.testing import *
|
||||
|
||||
try:
|
||||
from scikits.image.opencv import *
|
||||
OPENCV_LIBS_NOTFOUND = False
|
||||
except:
|
||||
OPENCV_LIBS_NOTFOUND = True
|
||||
|
||||
from scikits.image import data_dir
|
||||
|
||||
_opencv_skip = dec.skipif(OPENCV_LIBS_NOTFOUND,
|
||||
'OpenCV libraries not found')
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
from scikits.image import opencv
|
||||
|
||||
opencv_skip = dec.skipif(not opencv.libs_found,
|
||||
'OpenCV libraries not found')
|
||||
|
||||
class OpenCVTest:
|
||||
# setup only works as a module level function
|
||||
def __init__(self):
|
||||
self.lena_RGB_U8 = np.load(os.path.join(data_dir, 'lena_RGB_U8.npy'))
|
||||
self.lena_GRAY_U8 = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy'))
|
||||
|
||||
lena_RGB_U8 = np.load(os.path.join(data_dir, 'lena_RGB_U8.npy'))
|
||||
lena_GRAY_U8 = np.load(os.path.join(data_dir, 'lena_GRAY_U8.npy'))
|
||||
|
||||
class TestSobel(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvSobel(self):
|
||||
cvSobel(self.lena_GRAY_U8)
|
||||
|
||||
|
||||
class TestLaplace(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvLaplace(self):
|
||||
cvLaplace(self.lena_GRAY_U8)
|
||||
|
||||
|
||||
class TestCanny(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvCanny(self):
|
||||
cvCanny(self.lena_GRAY_U8)
|
||||
|
||||
|
||||
class TestPreCornerDetect(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvPreCornerDetect(self):
|
||||
cvPreCornerDetect(self.lena_GRAY_U8)
|
||||
|
||||
|
||||
class TestCornerEigenValsAndVecs(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvCornerEigenValsAndVecs(self):
|
||||
cvCornerEigenValsAndVecs(self.lena_GRAY_U8)
|
||||
|
||||
|
||||
class TestCornerMinEigenVal(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvCornerMinEigenVal(self):
|
||||
cvCornerMinEigenVal(self.lena_GRAY_U8)
|
||||
|
||||
|
||||
class TestCornerHarris(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvCornerHarris(self):
|
||||
cvCornerHarris(self.lena_GRAY_U8)
|
||||
|
||||
|
||||
class TestSmooth(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvSmooth(self):
|
||||
for st in (CV_BLUR_NO_SCALE, CV_BLUR, CV_GAUSSIAN, CV_MEDIAN,
|
||||
CV_BILATERAL):
|
||||
cvSmooth(self.lena_GRAY_U8, None, st, 3, 0, 0, 0, False)
|
||||
|
||||
class TestFindCornerSubPix:
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvFindCornersSubPix(self):
|
||||
img = np.array([[1, 1, 1, 0, 0, 0, 1, 1, 1],
|
||||
[1, 1, 1, 0, 0, 0, 1, 1, 1],
|
||||
@@ -92,13 +89,13 @@ class TestFindCornerSubPix:
|
||||
|
||||
|
||||
class TestGoodFeaturesToTrack(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvGoodFeaturesToTrack(self):
|
||||
cvGoodFeaturesToTrack(self.lena_GRAY_U8, 100, 0.1, 3)
|
||||
|
||||
|
||||
class TestResize(OpenCVTest):
|
||||
@_opencv_skip
|
||||
@opencv_skip
|
||||
def test_cvResize(self):
|
||||
cvResize(self.lena_RGB_U8, height=50, width=50, method=CV_INTER_LINEAR)
|
||||
cvResize(self.lena_RGB_U8, height=200, width=200, method=CV_INTER_CUBIC)
|
||||
|
||||
Reference in New Issue
Block a user