Python: CalcEMD2 error with cost matrix

asked 2014-02-21 13:23:10 -0600

klchan gravatar image

updated 2014-02-21 13:46:05 -0600

berak gravatar image

I am trying to use CalcEMD2 with a custom cost matrix instead of one of the standard metrics. I followed the documentation and tried the following inputs to CalcEMD2:

pre_sig1 = in1[..., None]/np.sum(in1)

pre_sig2 = in2[..., None]/np.sum(in2)

sig1 = cv.fromarray(np.require(np.float32(pre_sig1), requirements='CA'))

sig2 = cv.fromarray(np.require(np.float32(pre_sig2), requirements='CA'))

pre_cost = np.rad2deg(np.arccos(np.dot(vertices.T, vertices)))

pre_cost[np.isnan(pre_cost)] = 0

cost = cv.fromarray(np.float32(pre_cost))

EMD = cv.CalcEMD2(sig1, sig2, cv.CV_DIST_USER, cost_matrix = cost)

With this, I get the error: Only one of cost matrix or distance function should be non-NULL in case of user-defined distance

This doesn't seem to make sense to me since I didn't give it a distance function and the default distance function input is None. Is this my mistake or a bug?

edit retag flag offensive close merge delete

Comments

I have exactly the same problem. Did you find a solution?

slychief gravatar imageslychief ( 2014-06-24 04:06:30 -0600 )edit

@sylchief , i'm afraid, that this is still unsolved.

due to the way the python bindings are working currently, you can't use a cost matrix in python atm.

berak gravatar imageberak ( 2014-06-24 04:33:19 -0600 )edit