Ask Your Question

klchan's profile - activity

2014-06-24 04:05:14 -0500 received badge  Student (source)
2014-02-21 13:23:10 -0500 asked a question Python: CalcEMD2 error with cost matrix

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(, 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?