最近我一直在尝试用Python语言快速高效地执行两个数组的交叉相关检查。经过一些阅读,我找到了以下两个选项:
NumPy.correlate()
方法,在处理大型数组时速度太慢。cv.MatchTemplate()
方法似乎更快。
出于明显的原因,我选择了第二个选项。我尝试执行以下代码:
import scipy
import cv
image = cv.fromarray(scipy.float32(scipy.asarray([1,2,2,1])),allowND=True)
template = cv.fromarray(scipy.float32(scipy.asarray([2,2])),allowND=True)
result = cv.fromarray(scipy.float32(scipy.asarray([0,0,0])),allowND=True)
cv.MatchTemplate(image,template,result,cv.CV_TM_CCORR)
尽管这段代码看起来很简单,但它会抛出以下错误:
OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /builddir/build/BUILD/OpenCV-2.1.0/src/cxcore/cxarray.cpp, line 2476
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
cv.error: Unrecognized or unsupported array type
经过几个小时令人沮丧的尝试,我仍然卡住了!有没有人有什么建议?
顺便说一下,这是我的Python版本输出:
Python 2.7 (r27:82500, Sep 16 2010, 18:03:06)
[GCC 4.5.1 20100907 (Red Hat 4.5.1-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
谢谢大家!