BUG <cvSeqSort for OpenCV1.1pre1a>

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

BUG <cvSeqSort for OpenCV1.1pre1a>

mikelhlin
cvSeqSort does not seem to sort correctly when the number of items to
sort is greater than or equal to 8.

Here's my test code:
int comp( const void* a, const void* b, void* userdata )
{
       int* pa = (int*) a;
       int* pb = (int*) b;
       return *pa > *pb;
}

main()
{
              CvMemStorage* storage = cvCreateMemStorage(0);

               CvSeq* peaks = cvCreateSeq( CV_32SC1, sizeof(CvSeq),
sizeof(int), storage );
               int num[] = {9, 5, 1, 2, 0, 4,6, 8, 7};
               for(int i = 0; i < 9; i++)
               {
                       cvSeqPush(peaks, &num[i]);
               }
               cvSeqSort(peaks, comp, 0);
               for( int i = 0; i < peaks->total; i++ )
               {
                       int* n = (int*)cvGetSeqElem( peaks, i );
                       printf( "%d\n", *n);
               }
}


--
Mike Lin
Research Assistant
UBC Robotics and Control Lab


Reply | Threaded
Open this post in threaded view
|

Re: BUG <cvSeqSort for OpenCV1.1pre1a>

Peter Eisenlohr
mikelhlin wrote:

> cvSeqSort does not seem to sort correctly when the number of items to
> sort is greater than or equal to 8.
>
> Here's my test code:
> int comp( const void* a, const void* b, void* userdata )
> {
> int* pa = (int*) a;
> int* pb = (int*) b;
> return *pa > *pb;
> }

Your comparsion callback is wrong: You are supposed to return

  a negative integer if a < b,
  a positive integer if a > b and
  zero if a == b.

From the documentation:
/* a < b ? -1 : a > b ? 1 : 0 */

hth,
  Peter