From 4ab4213749cb90cec574c8e066b921e6e162279f Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Mon, 12 Dec 2011 20:19:15 -0500 Subject: [PATCH] Change OpenCV import to make it an optional dependency --- skimage/detection/_template.pyx | 2 +- skimage/detection/template.py | 10 +++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/skimage/detection/_template.pyx b/skimage/detection/_template.pyx index 3c6a726f..eb5a9733 100644 --- a/skimage/detection/_template.pyx +++ b/skimage/detection/_template.pyx @@ -3,9 +3,9 @@ import cython cimport numpy as np import numpy as np -import cv from scipy.signal import fftconvolve + cdef extern from "math.h": double sqrt(double x) double fabs(double x) diff --git a/skimage/detection/template.py b/skimage/detection/template.py index e0ad01ef..6bf02896 100644 --- a/skimage/detection/template.py +++ b/skimage/detection/template.py @@ -1,9 +1,15 @@ """template.py - Template matching """ import numpy as np -import cv import _template +try: + import cv + opencv_available = True +except ImportError: + opencv_available = False + + #XXX add to opencv backend once backend system in place def match_template_cv(image, template, out=None, method="norm-coeff"): @@ -23,6 +29,8 @@ def match_template_cv(image, template, out=None, method="norm-coeff"): Correlation results between 0.0 and 1.0, maximum indicating the most probable match. """ + if not opencv_available: + raise ImportError("Opencv 2.0+ required") if out == None: out = np.empty((image.shape[0] - template.shape[0] + 1, image.shape[1] - template.shape[1] + 1),