2017-10-18 118 views
0

简而言之,我想通过“形状上下文”匹配来比较不同的道路标记。形状上下文通过计算两种不同形状的距离的误差

我的第一个问题,你可以看到下:Matching shapes of road marking from OpenData

我解决了我的第一个问题,但现在看来一个新的错误。这里是我的代码:

import cv2 
import numpy as np 

# read data 
datapath = "/Users/output/test/"; 
a = cv2.imread(datapath+"template_orig.png"); 
b = cv2.imread(datapath+"template.png"); 

imgray_a = cv2.cvtColor(a,cv2.COLOR_BGR2GRAY) 
ret_a,thresh_a = cv2.threshold(imgray_a,127,255,0) 

imgray_b = cv2.cvtColor(b,cv2.COLOR_BGR2GRAY) 
ret_b,thresh_b = cv2.threshold(imgray_b,127,255,0) 


# find contours 
_, ca, _ = cv2.findContours(thresh_a, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE) 
_, cb, _ = cv2.findContours(thresh_b, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_SIMPLE) 
print(np.shape(ca[0]), np.shape(cb[0])) 

# generate distance --> Hausdorff OR ShapeContext 
hd = cv2.createHausdorffDistanceExtractor() 
sd = cv2.createShapeContextDistanceExtractor() 

d1 = hd.computeDistance(ca[0],cb[0]) 
d2 = sd.computeDistance(ca[0],cb[0]) 


print(d1, " ", d2) 

当我比较一个(原转弯箭头) enter image description hereb(提取旋转箭头)enter image description here不存在任何问题,当我比较一个c(其他任何测试“形状匹配”算法)enter image description here出现以下错误:

OpenCV Error: Assertion failed (type == CV_64FC2) in gemmImpl, file /Users/travis/build/skvark/opencv-python/opencv/modules/core/src/matmul.cpp, line 1218

Traceback (most recent call last): File "/test_shape.py", line 74, in d2 = sd.computeDistance(ca[0],cb[0])

cv2.error: /Users/travis/build/skvark/opencv-python/opencv/modules/core/src/matmul.cpp:1218: error: (-215) type == CV_64FC2 in function gemmImpl

错误只发生与“形状上下文”的产生距离的函数而不是与产生“的Hausdorff”的距离的函数

回答

0

好,我想问题是,即一个b一个ç没有像素的相同的高度(一个:131 X 32PX,b/C:29×18像素)。当我将bc的图像大小更改为像131 x 81 px这样的更高分辨率时,错误消失,正在计算“形状上下文”的距离。