Ask Your Question
0

OCV3 replacing static CV_IMPLEMENT_QSORT( icvSortDistances, int, CV_LT )

asked 2015-06-22 18:04:28 -0600

athundt gravatar image

I'm in the process of upgrading from opencv2.4.10 to opencv3, and there is a macro in use in one of the libraries I need that has been removed.

static CV_IMPLEMENT_QSORT( icvSortDistances, int, CV_LT )

What do I do to replace this?

edit retag flag offensive close merge delete

Comments

1

the definition is here

berak gravatar imageberak ( 2015-06-22 23:19:05 -0600 )edit

@berak Thanks for the definition! That helps, any advice on replacing it or am I better of simply copy/pasting the original code into my own tree?

athundt gravatar imageathundt ( 2015-06-23 14:02:01 -0600 )edit

well, the c/p solution is obviously the most simple (or , just put it into some header)

in the long run - i'm confused about:

a:) , why the codebase you mention duplicated the modelest.cpp (opencv2.4 had the very same file in calib3d)[was it in opencv even at the time, those guys wrote their code ?]

b:) why the whole code was removed from opencv in 3.0, and

c:) what would be the replacement for that legacy code as of today.

again, sorry, it's a bit over my head, all i can do is give you food for thought ;)

berak gravatar imageberak ( 2015-06-23 14:12:37 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-09-10 13:20:08 -0600

gregsmith_to gravatar image

updated 2015-09-10 13:23:46 -0600

I suspect it was removed because C++ has long had the same functionality in std::sort. For the use shown, add (if not already there)

#include <algorithm>

and replace the macro with

 static void
 icvSortDistances( int *array, size_t total, int /*unused*/ )
{
   std::sort( &array[0], &array[total] );
}

If you want to use the 'aux' parameter (passing info in to the compare) with std::sort, you need to define a little class with a method bool operator ()( T,T) const; you can put data in that class when constructing an instance of it, and you then pass the instance as a 3rd param to std::sort. That sort will call the operator() method to do compares, thus that method will be able to see the data. The operator()( a,b) should implement a<b for your sort - assuming you want increasing results.

Likewise if you want to sort e.g. floats in decreasing abs. value, you can make a little empty class with just the appropriate bool operator( float a , float b )const { return std::abs(a) > std::abs(b);} and pass an instance of that class as the 3rd parameter.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2015-06-22 18:04:28 -0600

Seen: 1,116 times

Last updated: Sep 10 '15