Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add cascade classifier operation #678

Merged
merged 13 commits into from
Oct 31, 2016

Conversation

SamCarlberg
Copy link
Member

@SamCarlberg SamCarlberg commented Oct 6, 2016

Also adds a new source for cascade classifiers

screenshot from 2016-10-10 15-14-28

Goals

  • Code generation
  • File source for choosing XML configuration files
  • Add operation to extract ROIs from the image (can be a separate PR)
  • Add additional inputs for finer control over the classifier

Also adds a new socket input view for file selection
@codecov-io
Copy link

codecov-io commented Oct 6, 2016

Current coverage is 53.92% (diff: 30.17%)

Merging #678 into master will decrease coverage by 0.55%

@@             master       #678   diff @@
==========================================
  Files           209        214     +5   
  Lines          6713       6882   +169   
  Methods           0          0          
  Messages          0          0          
  Branches        656        671    +15   
==========================================
+ Hits           3657       3711    +54   
- Misses         2886       3001   +115   
  Partials        170        170          

Sunburst

Powered by Codecov. Last update 1d02ed1...844a91c

this.infoLabel.setText("Found " + numRegions + " regions of interest");
});
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code seems eerily familiar, could this be refactored into the core (maybe behind an interface) with just a render method that takes a boolean showInputImage and also has a method like getDescriptionString?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy-pasted from the LinesReport preview, that's probably what you're thinking of. I'll pretty it up with a refactor later

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, if you move the render into core then it becomes incredibly easy for me to render as a web server too. Because then the code for creating the preview image will be in the core.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 08e53d3

* to the operations to resolve the file associated with the path.
*/
@XStreamAlias("grip:File")
public class FileSource extends Source {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would disagree with this pattern. I would make this a classifiers source.
Just like we don't expect steps to resolve paths for images that are loaded from the filesystem this too should behave the same.

@@ -39,11 +38,10 @@
private final ImageConverter imageConverter = new ImageConverter();
private final ImageView imageView = new ImageView();
private final Label infoLabel = new Label();
private final Mat tmp = new Mat();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to @ThomasJClark we cached the Mat in these classes because they were huge and were causing the memory usage of GRIP to grow at an incredibly fast rate and then the GC would kick in.
By caching the images in these temporary mats that we reused we were effectively re-using the same memory for each image rendered. If you can run a profiler and prove that this is not causing us to use more memory I'll allow this change, but you need to make sure of this.

*
* @return a mat with the data drawn on it
*/
public static <T> Mat draw(Mat image,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did like this solution, I just would have passed the tmp mat into it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not relevant to this PR. It can get refactored later, especially since #680 has to get merged ASAP

@SamCarlberg SamCarlberg changed the title Add cascade classfier operation Add cascade classifier operation Oct 10, 2016
@SamCarlberg
Copy link
Member Author

It'd be nice to have a Size input socket to avoid having one or two New Size steps for each cascade classifier. @JLLeitschuh thoughts?

OperationDescription.builder()
.name("Cascade Classifier")
.summary("Runs a cascade classifier on an image")
.icon(Icon.iconStream("opencv"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want a custom icon?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically a one-to-one mapping of an OpenCV function, so it's okay as is

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A nice icon for this feature would be nice.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's basically a one-to-one mapping of an OpenCV function

All the other OpenCV operations use the OpenCV icon. So this will use the OpenCV icon, too.

new SocketHint.Builder<>(Size.class)
.identifier("Max size")
.initialValue(new Size(0, 0))
.build();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Want to put these in the socket hints builder?

Copy link
Member Author

@SamCarlberg SamCarlberg Oct 10, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need, the default already initializes to (0, 0). I'm just going to use that

} catch (RuntimeException e) {
// Error with the config file, reset the classifier and throw an exception
classifier.load(lastFile);
throw new IllegalArgumentException("Invalid XML in configuration file", e);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The classifier should not be loaded from within the operation. The source should be the object instantiating the CascadeClassifier object

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think about this, if you ever want to add a HTTP source that creates a classifier then this won't work. Similarly, if someone sends one via network tables this won't work either.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, though I think that would have a negative impact on code generation because it would require users to manually instantiate the classifiers instead of having the pipeline handle everything

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cooooode gen!

@SamCarlberg SamCarlberg added this to the v1.5.0 milestone Oct 24, 2016
@JLLeitschuh
Copy link
Member

Is this ready to be merged?

@SamCarlberg
Copy link
Member Author

Yes

@JLLeitschuh
Copy link
Member

JLLeitschuh commented Oct 31, 2016

@SamCarlberg SamCarlberg merged commit 0d8f24f into WPIRoboticsProjects:master Oct 31, 2016
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants