mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-17 11:32:45 +08:00
Merged with trunk
This commit is contained in:
@@ -1,15 +1,9 @@
|
||||
import ctypes
|
||||
import warnings
|
||||
import sys
|
||||
|
||||
# try to open the opencv libs
|
||||
# prints a warning if the libs are not found
|
||||
from _libimport import cv
|
||||
|
||||
from opencv_constants import *
|
||||
|
||||
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
|
||||
from opencv_cv import *
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
#!/usr/bin/env python
|
||||
# encoding: utf-8
|
||||
|
||||
"""
|
||||
This file properly imports the open CV libraries and returns them
|
||||
as an object. This function goes a longer way to try to find them
|
||||
since especially on MacOS X Library Paths are not clearly defined.
|
||||
|
||||
This module also removes the code duplication in __init__ and
|
||||
opencv_cv
|
||||
"""
|
||||
|
||||
__all__ = [ "cv" ]
|
||||
|
||||
import ctypes
|
||||
import sys
|
||||
import warnings
|
||||
|
||||
def _import_opencv_lib(which = "cv"):
|
||||
"""
|
||||
Try to import a shared library of OpenCV.
|
||||
|
||||
which - Which library ["cv", "cxcore", "highgui"]
|
||||
"""
|
||||
if sys.platform.startswith("darwin"):
|
||||
shared_lib = _tryload_macosx(which)
|
||||
elif sys.platform.startswith("linux"):
|
||||
shared_lib = ctypes.CDLL('lib' + which + '.so')
|
||||
else:
|
||||
shared_lib = ctypes.CDLL(which + '.dll')
|
||||
|
||||
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.'))
|
||||
return shared_lib
|
||||
|
||||
def _tryload_macosx(which):
|
||||
common_paths = [
|
||||
'/lib/',
|
||||
'/usr/lib/',
|
||||
'/usr/local/lib/',
|
||||
'/opt/local/lib/', # MacPorts
|
||||
'/sw/lib/', # Fink
|
||||
]
|
||||
shared_lib = None
|
||||
for path in common_paths:
|
||||
try:
|
||||
libpath =path + "lib" + which + '.dylib'
|
||||
shared_lib = ctypes.CDLL(path + "lib" + which + '.dylib')
|
||||
break
|
||||
except OSError, e:
|
||||
if "image not found" in e.args[0]:
|
||||
continue
|
||||
raise
|
||||
|
||||
return shared_lib
|
||||
|
||||
|
||||
cv = _import_opencv_lib("cv")
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,7 +2,7 @@
|
||||
#############################################
|
||||
# Constants (need a better place for these)
|
||||
############################################
|
||||
|
||||
|
||||
|
||||
CV_BLUR_NO_SCALE = 0
|
||||
CV_BLUR = 1
|
||||
@@ -18,3 +18,15 @@ CV_INTER_NN = 0
|
||||
CV_INTER_LINEAR = 1
|
||||
CV_INTER_CUBIC = 2
|
||||
CV_INTER_AREA = 3
|
||||
|
||||
#########################
|
||||
# Calibration Constants #
|
||||
#########################
|
||||
CV_CALIB_USE_INTRINSIC_GUESS = 1
|
||||
CV_CALIB_FIX_ASPECT_RATIO = 2
|
||||
CV_CALIB_FIX_PRINCIPAL_POINT = 4
|
||||
CV_CALIB_ZERO_TANGENT_DIST = 8
|
||||
CV_CALIB_CB_ADAPTIVE_THRESH = 1
|
||||
CV_CALIB_CB_NORMALIZE_IMAGE = 2
|
||||
CV_CALIB_CB_FILTER_QUADS = 4
|
||||
|
||||
|
||||
+1709
-1340
File diff suppressed because it is too large
Load Diff
@@ -8,11 +8,10 @@ from opencv_backend import *
|
||||
from opencv_backend cimport *
|
||||
from opencv_constants import *
|
||||
|
||||
#one of these should work if the user imported the package properly
|
||||
try:
|
||||
cv = ctypes.CDLL('libcv.so')
|
||||
except OSError:
|
||||
cv = ctypes.CDLL('cv.dll')
|
||||
from opencv_constants import *
|
||||
from opencv_cv import *
|
||||
|
||||
from _libimport import cv
|
||||
|
||||
###################################
|
||||
# opencv function declarations
|
||||
@@ -65,6 +64,16 @@ cdef cvFindCornerSubPixPtr c_cvFindCornerSubPix
|
||||
c_cvFindCornerSubPix = (<cvFindCornerSubPixPtr*>
|
||||
<size_t>ctypes.addressof(cv.cvFindCornerSubPix))[0]
|
||||
|
||||
# cvFindChessboardCorners
|
||||
ctypedef void (*cvFindChessboardCornersPtr)(IplImage*, CvSize, CvPoint2D32f*, int*, int)
|
||||
cdef cvFindChessboardCornersPtr c_cvFindChessboardCorners
|
||||
c_cvFindChessboardCorners = (<cvFindChessboardCornersPtr*><size_t>ctypes.addressof(cv.cvFindChessboardCorners))[0]
|
||||
|
||||
# cvDrawChessboardCorners
|
||||
ctypedef void (*cvDrawChessboardCornersPtr)(IplImage*, CvSize, CvPoint2D32f*, int, int)
|
||||
cdef cvDrawChessboardCornersPtr c_cvDrawChessboardCorners
|
||||
c_cvDrawChessboardCorners = (<cvDrawChessboardCornersPtr*><size_t>ctypes.addressof(cv.cvDrawChessboardCorners))[0]
|
||||
|
||||
# cvSmooth
|
||||
ctypedef void (*cvSmoothPtr)(IplImage*, IplImage*, int, int,
|
||||
int, double, double)
|
||||
@@ -88,6 +97,70 @@ c_cvResize = (<cvResizePtr*><size_t>ctypes.addressof(cv.cvResize))[0]
|
||||
####################################
|
||||
# Function Implementations
|
||||
####################################
|
||||
def cvFindChessboardCorners(np.ndarray src, pattern_size, int flags = CV_CALIB_CB_ADAPTIVE_THRESH):
|
||||
"""
|
||||
Wrapper around the OpenCV cvFindChessboardCorners function.
|
||||
|
||||
src - Image to search for chessboard corners
|
||||
pattern_size - Tuple of inner corners (w,h)
|
||||
flags - directly passed through to OpenCV
|
||||
"""
|
||||
validate_array(src)
|
||||
|
||||
assert_nchannels(src, [1, 3])
|
||||
assert_dtype(src, [UINT8])
|
||||
|
||||
cdef np.npy_intp outshape[2]
|
||||
outshape[0] = <int> pattern_size[1]*pattern_size[0]
|
||||
outshape[1] = <int> 2 # pattern_size[0]
|
||||
|
||||
points = new_array(2, outshape, FLOAT32)
|
||||
cdef CvPoint2D32f* cvpoints = array_as_cvPoint2D32f_ptr(points)
|
||||
|
||||
cdef CvSize cvpattern_size
|
||||
cvpattern_size.height = pattern_size[1]
|
||||
cvpattern_size.width = pattern_size[0]
|
||||
|
||||
cdef IplImage srcimg
|
||||
populate_iplimage(src, &srcimg)
|
||||
|
||||
cdef int ncorners_found
|
||||
c_cvFindChessboardCorners(&srcimg, cvpattern_size, cvpoints, &ncorners_found, flags)
|
||||
|
||||
return points[:ncorners_found]
|
||||
|
||||
def cvDrawChessboardCorners(np.ndarray out, pattern_size, np.ndarray corners):
|
||||
"""
|
||||
Wrapper around the OpenCV cvDrawChessboardCorners function.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
out : ndarray, dim 3, dtype: uint8
|
||||
Image to draw into
|
||||
pattern_size : array_like, shape (2,)
|
||||
Number of inner corners (w,h)
|
||||
corners : ndarray, shape (n,2), dtype: float32
|
||||
Corners found in the image. See cvFindChessboardCorners and
|
||||
cvFindCornerSubPix
|
||||
"""
|
||||
validate_array(out)
|
||||
|
||||
assert_nchannels(out, [3])
|
||||
assert_dtype(out, [UINT8])
|
||||
|
||||
cdef CvSize cvpattern_size
|
||||
cvpattern_size.height = pattern_size[1]
|
||||
cvpattern_size.width = pattern_size[0]
|
||||
|
||||
cdef IplImage img
|
||||
populate_iplimage(out, &img)
|
||||
|
||||
cdef CvPoint2D32f* cvcorners = array_as_cvPoint2D32f_ptr(corners)
|
||||
|
||||
cdef int ncount = pattern_size[0]*pattern_size[1]
|
||||
c_cvDrawChessboardCorners(&img, cvpattern_size, cvcorners,
|
||||
ncount, <int> len(corners) == ncount)
|
||||
|
||||
def cvSobel(np.ndarray src, np.ndarray out=None, int xorder=1, int yorder=0,
|
||||
int aperture_size=3):
|
||||
|
||||
@@ -205,7 +278,6 @@ def cvCanny(np.ndarray src, np.ndarray out=None, double threshold1=10,
|
||||
|
||||
def cvPreCornerDetect(np.ndarray src, np.ndarray out=None,
|
||||
int aperture_size=3):
|
||||
|
||||
"""
|
||||
better doc string needed.
|
||||
for now:
|
||||
@@ -358,7 +430,6 @@ def cvFindCornerSubPix(np.ndarray src, np.ndarray corners, int count, win,
|
||||
if nbytes != (count * 2 * 4):
|
||||
raise ValueError('The number of declared points is different '
|
||||
'than exists in the array.')
|
||||
|
||||
cdef CvPoint2D32f* cvcorners = array_as_cvPoint2D32f_ptr(corners)
|
||||
|
||||
cdef CvSize cvwin
|
||||
@@ -549,3 +620,4 @@ def cvResize(np.ndarray src, height=None, width=None,
|
||||
c_cvResize(&srcimg, &outimg, method)
|
||||
|
||||
return out
|
||||
|
||||
|
||||
@@ -8,27 +8,27 @@ cdef struct _IplImage:
|
||||
int nChannels # number of channels 1, 2, 3 or 4
|
||||
int alphaChannel # ignored by opencv
|
||||
int depth # pixel depth in bits: IPL_DEPTH_8U, IPL_DEPTH_8S, IPL_DEPTH_16S, IPL_DEPTH_32S, IPL_DEPTH_32F, IPL_DEPTH_64F
|
||||
|
||||
|
||||
char colorModel[4] # ignored by opencv
|
||||
char channelSeq[4] # ignored by opencv
|
||||
int dataOrder # must be 0
|
||||
|
||||
|
||||
int origin # should be 0 for top-left origin
|
||||
|
||||
|
||||
int align # ignored by opencv
|
||||
|
||||
|
||||
int width # width in pixels
|
||||
int height # height in pixels
|
||||
|
||||
|
||||
void *roi # must be NULL
|
||||
void *maskROI # must be NULL
|
||||
void *maskROI # must be NULL
|
||||
void *imageId # must be NULL
|
||||
void *tileInfo # must be NULL
|
||||
int imageSize # image size in bytes
|
||||
|
||||
|
||||
char *imageData # pointer to the data
|
||||
int widthStep # row size in bytes (first stride of numpy array)
|
||||
int BorderMode[4] # ignored by opencv
|
||||
int BorderMode[4] # ignored by opencv
|
||||
int BorderConst[4] # ignored by opencv
|
||||
char* imageDataOrigin # pointer to origin of data. Used for deallocation, but python will handle this so we'll set it to void*
|
||||
|
||||
@@ -38,13 +38,13 @@ ctypedef _IplImage IplImage
|
||||
cdef struct CvPoint2D32f:
|
||||
float x
|
||||
float y
|
||||
|
||||
|
||||
cdef struct CvSize:
|
||||
int width
|
||||
int height
|
||||
|
||||
|
||||
cdef struct CvTermCriteria:
|
||||
int type
|
||||
int max_iter
|
||||
double epsilon
|
||||
|
||||
|
||||
|
||||
@@ -9,9 +9,9 @@ from scikits.image import data_dir
|
||||
|
||||
with warnings.catch_warnings():
|
||||
warnings.simplefilter("ignore")
|
||||
from scikits.image import opencv
|
||||
from scikits.image.opencv import *
|
||||
|
||||
opencv_skip = dec.skipif(not opencv.libs_found,
|
||||
opencv_skip = dec.skipif(cv is None,
|
||||
'OpenCV libraries not found')
|
||||
|
||||
class OpenCVTest:
|
||||
|
||||
Reference in New Issue
Block a user