gpt4 book ai didi

python - Shape Context Error 通过计算两个不同形状的距离

转载 作者:太空宇宙 更新时间:2023-11-03 22:46:15 25 4
gpt4 key购买 nike

简而言之,我想通过“形状上下文”匹配来比较不同的道路标记。

我的第一个问题你可以在下面看到: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)

当我比较a时(原来的转弯箭头) enter image description hereb(提取的转向箭头)enter image description here没有问题,但是当我比较ac(任何其他测试“形状匹配”算法)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

只有“shape context”的距离生成函数才会出错,“Hausdorff”的距离生成函数不会出错

最佳答案

好的,我认为问题是,abac 不具有相同的像素高度(a:131 x 32px,b/c:29 x 18 px)。当我将 bc 的图像大小时更改为更高分辨率(如 131 x 81 像素)时,错误消失并且正在计算“形状上下文”的距离。

关于python - Shape Context Error 通过计算两个不同形状的距离,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46808404/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com