public final class VisionPipeline<T>
- Object
- VisionPipeline
ImplementsAutoCloseable
Connects a camera frame stream to a reusable analyzer with keep-only-latest backpressure. At most one analysis and one pending frame are retained, so a slow model cannot build an unbounded queue. Results and errors arrive on the EDT. The pipeline owns and closes the analyzer but not the camera session.
Use this when the application already owns a CameraSession – it is
taking photos or recording video as well as analyzing. When the screen only
needs a preview that analyzes, VisionCameraView does the same thing
and owns the session too, which is one less lifecycle to get right.
CameraSession session = Camera.open(Camera.getDefault(CameraFacing.BACK),
new CameraSessionOptions().frameMaxFps(10).captureAudio(false));
form.add(BorderLayout.CENTER, session.createView());
VisionPipeline<Barcode[]> pipeline = new VisionPipeline<Barcode[]>(
session, new BarcodeScanner(),
new VisionPipelineListener<Barcode[]>() {
public void result(Barcode[] codes, VisionImage source) {
if (codes.length > 0) {
found(codes[0].getValue());
}
}
public void error(Throwable error) {
Log.e(error);
}
});
// Closing the pipeline detaches the frame listener and closes the
// analyzer. The session is yours to close.
form.addCloseListener(e -> {
pipeline.close();
session.close();
});
Constructors
public VisionPipeline(CameraSession session, VisionAnalyzer<T> analyzer, VisionPipelineListener<T> listener) | Attaches immediately as the session’s frame listener. |
Methods
public boolean isBusy() | Returns whether a frame is currently being analyzed. |
public void close() | Stops accepting frames, detaches from the camera session, discards the pending frame, clears the busy state, and closes the analyzer. |
Inherited methods
Constructor details
VisionPipeline
public VisionPipeline(CameraSession session, VisionAnalyzer<T> analyzer, VisionPipelineListener<T> listener)Attaches immediately as the session’s frame listener.
Parameters
sessionCameraSession- active camera session whose frames should be analyzed
analyzerVisionAnalyzer<T>- reusable analyzer owned by this pipeline
listenerVisionPipelineListener<T>- EDT result/error listener
Method details
isBusy
public boolean isBusy()Returns whether a frame is currently being analyzed.
Returns
true while the open pipeline has an analysis in flightclose
public void close()Stops accepting frames, detaches from the camera session, discards the
pending frame, clears the busy state, and closes the analyzer. A pending
frame already selected for dispatch is rechecked and discarded before
it can reach the closed analyzer. Calling this method more than once
has no effect.