Updated by Andrey Kamaev almost 13 years ago
The following Python script gives result 0, but 1.0 is expected.
However, if you add @lower_bound=float('inf')@ lower_bound=float('inf') to the calling of @CalcEMD2@, CalcEMD2, you will be able to get correct result.
This is probably because lower_bound is set to 0 instead of a @NULL@ NULL pointer in the Python wrapper, which causes the actual @cvCalcEMD2@ cvCalcEMD2 implementation skips EMD calculation, since the lower bound in the below test case is just 0.
<pre><code class="python"> <pre>
import cv
def toSig(b):
m = cv.CreateMat(len(b), 2, cv.CV_32FC1)
for i, x in enumerate(b):
m[i, 0] = 1
m[i, 1] = x
return m
def test():
b1 = [0,0,0,0]
b2 = [-1, 1, 1, -1]
s1 = toSig(b1)
s2 = toSig(b2)
print cv.CalcEMD2(s1, s2, cv.CV_DIST_L1)
#To get correct result:
#print cv.CalcEMD2(s1, s2, cv.CV_DIST_L1, lower_bound=float('inf'))
test()
</code></pre> </pre>
However, if you add @lower_bound=float('inf')@ lower_bound=float('inf') to the calling of @CalcEMD2@, CalcEMD2, you will be able to get correct result.
This is probably because lower_bound is set to 0 instead of a @NULL@ NULL pointer in the Python wrapper, which causes the actual @cvCalcEMD2@ cvCalcEMD2 implementation skips EMD calculation, since the lower bound in the below test case is just 0.
<pre><code class="python"> <pre>
import cv
def toSig(b):
m = cv.CreateMat(len(b), 2, cv.CV_32FC1)
for i, x in enumerate(b):
m[i, 0] = 1
m[i, 1] = x
return m
def test():
b1 = [0,0,0,0]
b2 = [-1, 1, 1, -1]
s1 = toSig(b1)
s2 = toSig(b2)
print cv.CalcEMD2(s1, s2, cv.CV_DIST_L1)
#To get correct result:
#print cv.CalcEMD2(s1, s2, cv.CV_DIST_L1, lower_bound=float('inf'))
test()
</code></pre> </pre>