Python CalcEMD2 gives wrong result (Bug #1763)


Added by Haoyu Bai almost 13 years ago. Updated almost 13 years ago.


Status:Done Start date:2012-04-05
Priority:High Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:python bindings
Target version:2.4.0
Affected version: Operating System:
Difficulty: HW Platform:
Pull request:

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

Revision a110dc14
Added by Vadim Pisarevsky almost 13 years ago

fixed bug in Python's calcEMD2 (ticket #1763)

Revision 0fb62991
Added by Roman Donchenko over 11 years ago

Merge pull request #1763 from SpecLad:cv-func

Revision bfa40e18
Added by Roman Donchenko over 11 years ago

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

Also available in: Atom PDF