Skip to content

Commit

Permalink
Finish merge of CvPipeline variables in code that had not yet been mi…
Browse files Browse the repository at this point in the history
…grated.
  • Loading branch information
vonnieda committed Jun 29, 2017
1 parent 87cd3e3 commit fc08fc6
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 41 deletions.
22 changes: 22 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,28 @@ a complete change list, only those that may directly interest or affect users.

# 2017-06-28

* CvPipeline Properties (Breaking Change)

In an effort to make it easier for developers to integrate custom functionality in CvPipelines,
the pipeline now has a map of properties that can be set be callers. This allows callers of
a pipeline to feed values in for the pipeline to use. This can be things like cameras, feeders,
parts, nozzles, etc.

This functionality replaces the previously added setFeeder and setNozzle calls. These calls
were too specific to certain pipelines and did not represent a good development direction
for the pipeline as it would eventually become cluttered with variables that did not
make sense for the pipeline as a whole.

Breaking Change: All existing stages have been migrated to the property system. If you have
custom stages that used getNozzle or getFeeder you will need to make minor updates to switch
these to use properties instead.

* getNozzle() becomes (Nozzle) getProperty("nozzle")
* getFeeder() becomes (Feeder) getProperty("feeder")

Finally, this change is the first step into supporting variables in CvPipeline. Eventually
you will be able to reference proeprties and other objects when setting parameters in stages.
* AdvancedLoosePartFeeder

ReferenceLoosePartFeeder has received a big upgrade thanks to @dzach. The
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ public void feed(Nozzle nozzle) throws Exception {

private Location getPickLocation(Camera camera, Nozzle nozzle) throws Exception {
// Process the pipeline to extract RotatedRect results
pipeline.setCamera(camera);
pipeline.setNozzle(nozzle);
pipeline.setFeeder(this);
pipeline.setProperty("camera", camera);
pipeline.setProperty("nozzle", nozzle);
pipeline.setProperty("feeder", this);
pipeline.process();
// Grab the results
List<RotatedRect> results = (List<RotatedRect>) pipeline.getResult("results").model;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public AdvancedLoosePartFeederConfigurationWizard(AdvancedLoosePartFeeder feeder

private void editPipeline() throws Exception {
CvPipeline pipeline = feeder.getPipeline();
pipeline.setCamera(Configuration.get().getMachine().getDefaultHead().getDefaultCamera());
pipeline.setFeeder(feeder);
pipeline.setProperty("camera", Configuration.get().getMachine().getDefaultHead().getDefaultCamera());
pipeline.setProperty("feeder", feeder);
CvPipelineEditor editor = new CvPipelineEditor(pipeline);
JDialog dialog = new JDialog(MainFrame.get(), feeder.getPart().getId() + " Pipeline");
dialog.getContentPane().setLayout(new BorderLayout());
Expand All @@ -121,8 +121,8 @@ private void resetPipeline() {

private void editTrainingPipeline() throws Exception {
CvPipeline pipeline = feeder.getTrainingPipeline();
pipeline.setCamera(Configuration.get().getMachine().getDefaultHead().getDefaultCamera());
pipeline.setFeeder(feeder);
pipeline.setProperty("camera", Configuration.get().getMachine().getDefaultHead().getDefaultCamera());
pipeline.setProperty("feeder", feeder);
CvPipelineEditor editor = new CvPipelineEditor(pipeline);
JDialog dialog = new JDialog(MainFrame.get(), feeder.getPart().getId() + " Training Pipeline");
dialog.getContentPane().setLayout(new BorderLayout());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.opencv.highgui.Highgui;
import org.openpnp.model.Configuration;
import org.openpnp.spi.Camera;
import org.openpnp.spi.Feeder;
import org.openpnp.vision.pipeline.CvPipeline;
import org.openpnp.vision.pipeline.CvStage;
import org.openpnp.vision.pipeline.Property;
Expand Down Expand Up @@ -119,9 +120,9 @@ public Result process(CvPipeline pipeline) throws Exception {
}
}
else {
Feeder feeder = (Feeder) pipeline.getProperty("feeder");
// path is assumed to be a directory containing template images
if (pipeline.getFeeder() == null || pipeline.getFeeder()
.getPart() == null) {
if (feeder == null || feeder.getPart() == null) {
if (log) {
Logger.info(
"No feeder, part, or useable templateFile found. Cannot figure out part name.");
Expand All @@ -131,17 +132,15 @@ public Result process(CvPipeline pipeline) throws Exception {
if (!filepath.endsWith(File.separator)) {
filepath += File.separator;
}
filename = filepath + pipeline.getFeeder()
.getPart()
.getId()
filename = filepath + feeder.getPart()
.getId()
+ extension;
file = new File(filename);
if (!file.exists()) {
// try the package id
filename = filepath + pipeline.getFeeder()
.getPart()
.getPackage()
.getId()
filename = filepath + feeder.getPart()
.getPackage()
.getId()
+ extension;
file = new File(filename);
if (!file.exists()) {
Expand All @@ -150,20 +149,17 @@ public Result process(CvPipeline pipeline) throws Exception {
// TODO: it would be best if we could define a package outline, e.g. as a
// polygon
// and use that to draw the part and match templates
if (pipeline.getFeeder()
.getPart()
.getPackage()
.getFootprint() != null) {
width = pipeline.getFeeder()
.getPart()
.getPackage()
.getFootprint()
.getBodyWidth();
height = pipeline.getFeeder()
.getPart()
.getPackage()
.getFootprint()
.getBodyHeight();
if (feeder.getPart()
.getPackage()
.getFootprint() != null) {
width = feeder.getPart()
.getPackage()
.getFootprint()
.getBodyWidth();
height = feeder.getPart()
.getPackage()
.getFootprint()
.getBodyHeight();
if (width == 0 || height == 0) {
if (log) {
Logger.info("Package body dimensions are not set.");
Expand All @@ -178,7 +174,7 @@ public Result process(CvPipeline pipeline) throws Exception {
height = tmp;
}
// get length conversion value from camera
Camera camera = pipeline.getCamera();
Camera camera = (Camera) pipeline.getProperty("camera");
width /= camera.getUnitsPerPixel()
.getX();
height /= camera.getUnitsPerPixel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import org.opencv.highgui.Highgui;
import org.openpnp.model.Configuration;
import org.openpnp.spi.Feeder;
import org.openpnp.vision.pipeline.CvPipeline;
import org.openpnp.vision.pipeline.CvStage;
import org.openpnp.vision.pipeline.Property;
Expand Down Expand Up @@ -111,9 +112,8 @@ public Result process(CvPipeline pipeline) throws Exception {

// path is assumed to be a directory containing template images
// check if a part ID can be found from the feeder this pipeline may belong to

if (pipeline.getFeeder() == null || pipeline.getFeeder()
.getPart() == null) {
Feeder feeder = (Feeder) pipeline.getProperty("feeder");
if (feeder == null || feeder.getPart() == null) {

throw new Exception(
"No part in feeder. Please provide create template image file path.");
Expand All @@ -126,16 +126,14 @@ public Result process(CvPipeline pipeline) throws Exception {
filepath += File.separator;
}
if (asPackage) {
filepath += pipeline.getFeeder()
.getPart()
.getPackage()
.getId()
filepath += feeder.getPart()
.getPackage()
.getId()
+ extension;
}
else {
filepath += pipeline.getFeeder()
.getPart()
.getId()
filepath += feeder.getPart()
.getId()
+ extension;
}
file = new File(filepath);
Expand Down

0 comments on commit fc08fc6

Please sign in to comment.