0

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 a is the original turn arrow and b 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

freddykrueger
  • 309
  • 4
  • 17
  • does both of them fail? i mean the hd and sd? can you try commenting it to see if both fails? I ask this, since there is an [open bug](https://github.com/opencv/opencv/issues/5076) that could be related to this (maybe not) – api55 Oct 17 '17 at 12:50
  • I've updated/edited my question ;) Do you have an idea in terms of the error? (Because I'm new, I can't add new links/pictures --> that's why the picture of "c" is in brackets – freddykrueger Oct 17 '17 at 13:04
  • now the error is different. If you have new questions is better to open a new question. If you solved the other problem is good to answer yourself so people find it easierly. About his problem, looks like it was given the wrong type? maybe you can double check that is not empty, or that it has the same type as the one previous working ones – api55 Oct 17 '17 at 13:55
  • Is a C++ related error. First make sure the two images have the same number of channels. In other words, shape should be the same. Also, can you check the type of the images? gemmImpl uses float I believe. – Javier Oct 17 '17 at 20:28
  • My new question is online under: https://stackoverflow.com/questions/46808404/shape-context-error-by-calculating-distance-of-two-different-shapes – freddykrueger Oct 18 '17 at 11:24

0 Answers0