I've been programmed to love you.
Home
Go Back   Chief Delphi > Technical > Programming > Java
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Spotlight this post!  
Unread 07-02-2017, 06:58
pblankenbaker pblankenbaker is offline
Registered User
FRC #0868
 
Join Date: Feb 2012
Location: Carmel, IN, USA
Posts: 124
pblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of lightpblankenbaker is a glorious beacon of light
Re: Sort array in filterContours

When sorting objects with the Collections.sort() method, you will typically want to supply the "comparator" parameter that lets you control the comparison between each object (decide which should come before the other).

For example, if you want to sort by area, I think you can use a static helper method something like the following:

Code:
  public static void sortContoursByArea(List<MatOfPoint> contours) {
    Collections.sort(contours, new Comparator<MatOfPoint>() {

      @Override
      public int compare(MatOfPoint a, MatOfPoint b) {
        // Not sure how expensive this will be computationally as the
        // area is computed for each comparison
        double areaA = Imgproc.contourArea(a);
        double areaB = Imgproc.contourArea(b);

        // Change sign depending on whether your want sorted small to big
        // or big to small
        if (areaA < areaB) {
          return -1;
        } else if (areaA > areaB) {
          return 1;
        }
        return 0;
      }
    });
  }
Hope that helps
Reply With Quote
 


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -5. The time now is 15:34.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi