Python CalcEMD2 gives wrong result (Bug #1763)
Description
The following Python script gives result 0, but 1.0 is expected.
However, if you add lower_bound=float('inf')
to the calling of CalcEMD2
, you will be able to get correct result.
This is probably because lower_bound is set to 0 instead of a NULL
pointer in the Python wrapper, which causes the actual cvCalcEMD2
implementation skips EMD calculation, since the lower bound in the below test case is just 0.
1import cv
2
3def toSig(b):
4 m = cv.CreateMat(len(b), 2, cv.CV_32FC1)
5 for i, x in enumerate(b):
6 m[i, 0] = 1
7 m[i, 1] = x
8 return m
9
10def test():
11 b1 = [0,0,0,0]
12 b2 = [-1, 1, 1, -1]
13
14 s1 = toSig(b1)
15 s2 = toSig(b2)
16 print cv.CalcEMD2(s1, s2, cv.CV_DIST_L1)
17 #To get correct result:
18 #print cv.CalcEMD2(s1, s2, cv.CV_DIST_L1, lower_bound=float('inf'))
19
20test()
Associated revisions
fixed bug in Python's calcEMD2 (ticket #1763)
Merge pull request #1763 from SpecLad:cv-func
Removed another usage of func, following #1763.
History
Updated by Haoyu Bai almost 13 years ago
Note that this only happens with Python wrapper. The C++ wrapper gives correct result.
Updated by Andrey Kamaev almost 13 years ago
- Description changed from The following Python script gives result 0, but 1.0 is expected. However, if... to The following Python script gives result 0, but 1.0 is expected. However, if... More
- Category set to python bindings
Updated by Vadim Pisarevsky almost 13 years ago
thanks! fixed in r8182
Updated by Vadim Pisarevsky almost 13 years ago
- Status changed from Open to Done
- Target version set to 2.4.0
- Assignee set to Vadim Pisarevsky