Nothing in the KOP can prepare me for 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

 
Reply
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 07-02-2017, 10:03
SamCarlberg's Avatar
SamCarlberg SamCarlberg is offline
GRIP, WPILib. 2084 alum
FRC #2084
Team Role: Mentor
 
Join Date: Nov 2015
Rookie Year: 2009
Location: MA
Posts: 169
SamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to behold
Re: Sort array in filterContours

FWIW you could also write that as

Code:
public static void sortContoursByArea(List<MatOfPoint> contours) {
  Collections.sort(contours, Comparator.comparingDouble(Imgproc::contourArea));
}
__________________
WPILib
GRIP, RobotBuilder
Reply With Quote
  #2   Spotlight this post!  
Unread 07-02-2017, 12:13
PhilBot's Avatar
PhilBot PhilBot is offline
Get a life? This IS my life!
AKA: Phil Malone
FRC #1629 (GaCo: The Garrett Coalition)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Maryland
Posts: 756
PhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond repute
Re: Sort array in filterContours

Quote:
Originally Posted by SamCarlberg View Post
FWIW you could also write that as

Code:
public static void sortContoursByArea(List<MatOfPoint> contours) {
  Collections.sort(contours, Comparator.comparingDouble(Imgproc::contourArea));
}
That's a really interesting syntax.

Is there a name for what is hapening with "Imgproc::contourArea" ?
I'd like to look up the explanation of how that works...

Clearly it's getting expanded internally into Imgprog.contourArea(contours[n]) for the comparison.... but I don't know how/why.....
__________________
Phil Malone
Garrett Engineering And Robotics Society (GEARS) founder.
http://www.GEARSinc.org

FRC1629 Mentor, FTC2818 Coach, FTC4240 Mentor, FLL NeXTGEN Mentor
Reply With Quote
  #3   Spotlight this post!  
Unread 07-02-2017, 13:12
SamCarlberg's Avatar
SamCarlberg SamCarlberg is offline
GRIP, WPILib. 2084 alum
FRC #2084
Team Role: Mentor
 
Join Date: Nov 2015
Rookie Year: 2009
Location: MA
Posts: 169
SamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to beholdSamCarlberg is a splendid one to behold
Re: Sort array in filterContours

That's called a method reference.

This article explains it quite well

Also, you don't even need a special method for sorting a list. The List interface defines a method "sort(Comparator)" that you can use inline like

Code:
contours.sort(Comparator.comparingDouble(Imgproc::contourArea));
__________________
WPILib
GRIP, RobotBuilder
Reply With Quote
  #4   Spotlight this post!  
Unread 07-02-2017, 14:01
PhilBot's Avatar
PhilBot PhilBot is offline
Get a life? This IS my life!
AKA: Phil Malone
FRC #1629 (GaCo: The Garrett Coalition)
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Maryland
Posts: 756
PhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond reputePhilBot has a reputation beyond repute
Re: Sort array in filterContours

Quote:
Originally Posted by SamCarlberg View Post
That's called a method reference.

This article explains it quite well

Also, you don't even need a special method for sorting a list. The List interface defines a method "sort(Comparator)" that you can use inline like

Code:
contours.sort(Comparator.comparingDouble(Imgproc::contourArea));
Dang... As an "vintage" programmer, it's sometimes scary when I realize how much I don't know about the "newer" languages. That's pretty darn powerful.
__________________
Phil Malone
Garrett Engineering And Robotics Society (GEARS) founder.
http://www.GEARSinc.org

FRC1629 Mentor, FTC2818 Coach, FTC4240 Mentor, FLL NeXTGEN Mentor
Reply With Quote
Reply


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