/** * Builds and returns the Pipeline which represents the actual computation. */ private static Pipeline buildPipeline(String modelPath) { Pipeline pipeline = Pipeline.create(); pipeline.drawFrom(WebcamSource.webcam(500)) .mapUsingContext(classifierContext(modelPath), (ctx, img) -> { Entry<String, Double> classification = classifyWithModel(ctx, img); return tuple3(img, classification.getKey(), classification.getValue()); } ) .window(tumbling(1000)) .aggregate(maxBy(comparingDouble(Tuple3::f2))) .drainTo(buildGUISink()); return pipeline; }