Matching shapes of road marking from OpenData

女生的网名这么多〃 提交于 2019-12-13 03:50:46

问题


for now I work on the generation of road marking from OpenData. Because I'm a Newbie in programming I use Python. I process orthophotos and transform them to binary-photos (only black and white pixels). After that I get such a photo like this:

The next step is to recognize various road marking on the given example picture. I think this should be possible by "shape context matching".

So I wrote this code (a is the original turn arrow and b is a extracted turn arrow from the example picture) to compare here various turn arrows with the original turn arrow:

import cv2
import numpy as np

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

# find contours
ca = cv2.findContours(a, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_TC89_KCOS)
cb = cv2.findContours(b, cv2.RETR_CCOMP, cv2.CHAIN_APPROX_TC89_KCOS)
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

But when I want to perform my code, it says:

cv2.error: /Users/travis/build/skvark/opencv-python/opencv/modules/shape/src/haus_dis.cpp:139: error: (-215) (set1.channels()==2) && (set1.cols>0) in function computeDistance

Is it furthermore a problem that the resolution of "a" is: 32 x 131 px and the resolution of "b" is: 18 x 29 px?

Thanks for your effort :)


EDIT:

I change my code to the following:

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

The result of the comparison of a and b is: d1 = 28.4604988098, d2 = 0.320339113474

But when I compare a with e.g. c (

) the program stops with the following error:

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

来源:https://stackoverflow.com/questions/46788883/matching-shapes-of-road-marking-from-opendata

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!