Change OpenCV import to make it an optional dependency

This commit is contained in:
Tony S Yu
2012-05-08 21:28:50 -04:00
parent d43049da71
commit 4ab4213749
2 changed files with 10 additions and 2 deletions
+1 -1
View File
@@ -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)
+9 -1
View File
@@ -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),