diff --git a/.gitignore b/.gitignore index d9bc1b6a..a4ae5eba 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ doc/source/api doc/build source/api scikits/image/opencv/*.so +scikits/image/opencv/*.bak diff --git a/scikits/image/opencv/tests/data/lena.png b/scikits/image/data/lena.png similarity index 100% rename from scikits/image/opencv/tests/data/lena.png rename to scikits/image/data/lena.png diff --git a/scikits/image/opencv/tests/data/lena_GRAY_U8.npy b/scikits/image/data/lena_GRAY_U8.npy similarity index 100% rename from scikits/image/opencv/tests/data/lena_GRAY_U8.npy rename to scikits/image/data/lena_GRAY_U8.npy diff --git a/scikits/image/opencv/tests/data/lena_RGB_U8.npy b/scikits/image/data/lena_RGB_U8.npy similarity index 100% rename from scikits/image/opencv/tests/data/lena_RGB_U8.npy rename to scikits/image/data/lena_RGB_U8.npy diff --git a/scikits/image/opencv/tests/data/lenagray.png b/scikits/image/data/lenagray.png similarity index 100% rename from scikits/image/opencv/tests/data/lenagray.png rename to scikits/image/data/lenagray.png diff --git a/scikits/image/opencv/INSTALL.txt b/scikits/image/opencv/INSTALL.txt index f142522e..4667f743 100644 --- a/scikits/image/opencv/INSTALL.txt +++ b/scikits/image/opencv/INSTALL.txt @@ -1,4 +1,6 @@ -Until we come to a solution for a setup.py, execute the included shell script build.sh +You can try to use the setup.py but it may still be broken + +Until we come to a solution for a setup.py, execute the included shell script build.sh and copy the .so's to wherever you want them scikit/image/opencv$./build.sh scikit/image/opencv$cd tests diff --git a/scikits/image/opencv/LICENSE.txt b/scikits/image/opencv/LICENSE.txt new file mode 100644 index 00000000..da93603f --- /dev/null +++ b/scikits/image/opencv/LICENSE.txt @@ -0,0 +1,28 @@ +Copyright (C) 2009 Steven C. Colbert +All rights reserved. + +Redistribution and use in source and binary forms, with or without +modification, are permitted provided that the following conditions are +met: + + 1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in + the documentation and/or other materials provided with the + distribution. + 3. Neither the name of scikits.image nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. diff --git a/scikits/image/opencv/opencv_backend.c b/scikits/image/opencv/opencv_backend.c index 462980a8..c4c9ba18 100644 --- a/scikits/image/opencv/opencv_backend.c +++ b/scikits/image/opencv/opencv_backend.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.3 on Tue Oct 13 00:28:25 2009 */ +/* Generated by Cython 0.11.3 on Wed Oct 14 12:47:10 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" diff --git a/scikits/image/opencv/opencv_cv.c b/scikits/image/opencv/opencv_cv.c index 6a150881..c851b589 100644 --- a/scikits/image/opencv/opencv_cv.c +++ b/scikits/image/opencv/opencv_cv.c @@ -1,4 +1,4 @@ -/* Generated by Cython 0.11.3 on Tue Oct 13 00:28:27 2009 */ +/* Generated by Cython 0.11.3 on Wed Oct 14 12:47:11 2009 */ #define PY_SSIZE_T_CLEAN #include "Python.h" diff --git a/scikits/image/opencv/setup.py b/scikits/image/opencv/setup.py new file mode 100644 index 00000000..01ba61f3 --- /dev/null +++ b/scikits/image/opencv/setup.py @@ -0,0 +1,72 @@ +#!/usr/bin/env python + +import os +import shutil + +current_dir = os.path.dirname(__file__) + +def configuration(parent_package='', top_path=None): + from numpy.distutils.misc_util import Configuration, get_numpy_include_dirs + config = Configuration('opencv', parent_package, top_path) + + config.add_data_dir(os.path.join(current_dir, 'tests')) + + # since distutils/cython has problems, we'll check to see if cython is + # installed and use that to rebuild the .c files, if not, we'll just build + # direct from the included .c files + + # if the cython compilation fails, it will overwrite the good .c files + # so we back them up first + + src = os.path.join(current_dir, 'opencv_cv.c') + dst = os.path.join(current_dir, 'opencv_cv.c.bak') + shutil.copy(src, dst) + src = os.path.join(current_dir, 'opencv_backend.c') + dst = os.path.join(current_dir, 'opencv_backend.c.bak') + shutil.copy(src, dst) + + try: + import cython + # no way to check the cython version number???? + os.system('cython opencv_backend.pyx') + os.system('cython opencv_cv.pyx') + + # if the cython compilation failed, the resulting file + # size will be very small ~ 78 bytes + f1 = os.path.join(current_dir, 'opencv_cv.c') + f2 = os.path.join(current_dir, 'opencv_backend.c') + size1 = os.path.getsize(f1) + size2 = os.path.getsize(f2) + assert size1 > 100 and size2 > 100 + except: + print 'Cython compilation failed. Building from backups.' + src = os.path.join(current_dir, 'opencv_cv.c.bak') + dst = os.path.join(current_dir, 'opencv_cv.c') + shutil.copy(src, dst) + src = os.path.join(current_dir, 'opencv_backend.c.bak') + dst = os.path.join(current_dir, 'opencv_backend.c') + shutil.copy(src, dst) + + config.add_extension('opencv_backend', sources=['opencv_backend.c'], + include_dirs=[get_numpy_include_dirs()]) + + config.add_extension('opencv_cv', sources=['opencv_cv.c'], + include_dirs=[get_numpy_include_dirs()]) + + return config + +if __name__ == '__main__': + from numpy.distutils.core import setup + setup(maintainer = 'Scikits.Image Developers', + author = 'Steven C. Colbert', + maintainer_email = 'scikits-image@googlegroups.com', + description = 'OpenCV wrapper for NumPy arrays', + url = 'http://stefanv.github.com/scikits.image/', + license = 'SciPy License (BSD Style)', + **(configuration(top_path='').todict()) + ) + + + + + \ No newline at end of file diff --git a/scikits/image/opencv/tests/test_opencv_backend.py b/scikits/image/opencv/tests/test_opencv_backend.py deleted file mode 100644 index e69de29b..00000000 diff --git a/scikits/image/opencv/tests/test_opencv_cv.py b/scikits/image/opencv/tests/test_opencv_cv.py index de51e080..aef35d98 100644 --- a/scikits/image/opencv/tests/test_opencv_cv.py +++ b/scikits/image/opencv/tests/test_opencv_cv.py @@ -1,5 +1,5 @@ # test for the opencv_cv extension module - +import os import numpy as np from numpy.testing import * @@ -9,6 +9,8 @@ try: except: OPENCV_LIBS_NOTFOUND = True +from scikits.image import data_dir + _opencv_skip = dec.skipif(OPENCV_LIBS_NOTFOUND, 'Skipping OpenCV test because OpenCV' 'libs were not found') @@ -16,8 +18,8 @@ _opencv_skip = dec.skipif(OPENCV_LIBS_NOTFOUND, class OpenCVTest: # setup only works as a module level function def __init__(self): - self.lena_RGB_U8 = np.load('data/lena_RGB_U8.npy') - self.lena_GRAY_U8 = np.load('data/lena_GRAY_U8.npy') + 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')) class TestSobel(OpenCVTest):