【发布时间】:2018-09-16 00:16:04
【问题描述】:
我正在尝试使用 Python 制作虹膜扫描仪并打开 CV。使用模板匹配功能时出现以下错误:
import cv2
import numpy as np
img1 = cv2.imread('canny.jpg');
img2 = cv2.imread('frame1.jpg');
edges=cv2.Canny(img2,100,100)
w,h=edges.shape[::-1]
res = cv2.matchTemplate(img1 , edges, cv2.TM_CCOEFF_NORMED)
threshold = 0.8
loc = np.where(res >= threshold)
print loc
以下是错误:
Traceback (most recent call last):
File "E:/OpenCV Programs/threshold2img1.py", line 9, in <module>
res = cv2.matchTemplate(img1 , edges, cv2.TM_CCOEFF_NORMED)
error: OpenCV(3.4.1) C:\build\master_winpack-bindings-win32-vc14-static\opencv\modules\imgproc\src\templmatch.cpp:1102: error: (-215) (depth == 0 || depth == 5) && type == _templ.type() && _img.dims() <= 2 in function cv::matchTemplate
【问题讨论】:
-
如此紧急以至于您没有时间将错误消息输入到像谷歌这样的网络搜索中?有很多解决方案....
-
因为您使用的是不同形状的图像。 canny edge 的形状为 (m,n) 而 img1 的形状为 (m,n,3)
-
我不确定你是怎么想出这个办法的。在精明的眼睛图像上使用这种模板匹配不太可能获得任何好的结果。你知道这个函数是做什么的吗?
标签: python python-2.7 opencv image-processing iris-recognition