Class VisionOptions
Common analyzer configuration. An analyzer captures the supplied options when constructed; reuse it for frames needing the same backend, confidence threshold, and result limit.
ImageLabeler labeler = new ImageLabeler(new VisionOptions()
.minimumConfidence(0.6f) // drop guesses below 60%
.maximumResults(5)); // keep the top five labels
The analyzer snapshots these values, so mutating the options object
afterwards changes nothing -- construct a second analyzer instead. Not
every analyzer reads every setting: textScript(TextScript) applies
only to TextRecognizer, and a backend may ignore a limit it has no
way to enforce.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbackend(VisionBackend value) barcodeFormats(String... values) LimitsBarcodeScannerto the givenBarcodeFormatconstants.String[]intfloatbooleanisStrictBarcode(String format) Whether a code of the given format must be read identically twice.booleanmaximumResults(int value) Sets a non-negative result limit; zero means backend default/unlimited.minimumConfidence(float value) Sets the confidence threshold, clamped to 0..1.strictBarcodes(boolean value) Makes aBarcodeScannerreport a code only once two frames have read it identically.textScript(TextScript value) Selects the writing systemTextRecognizershould read.
-
Constructor Details
-
VisionOptions
public VisionOptions()
-
-
Method Details
-
backend
- Parameters:
value- selector, ornullto restore automatic selection- Returns:
- this options object
-
textScript
Selects the writing systemTextRecognizershould read. Analyzers other than the text recognizer ignore it.- Parameters:
value- script selector, ornullfor the platform default (Latin)- Returns:
- this options object
-
minimumConfidence
Sets the confidence threshold, clamped to 0..1. NaN has no meaningful ordering and is rejected instead of being passed to platform detectors.- Parameters:
value- requested threshold- Returns:
- this options object
- Throws:
IllegalArgumentException- ifvalueis NaN
-
maximumResults
Sets a non-negative result limit; zero means backend default/unlimited.- Parameters:
value- requested limit- Returns:
- this options object
-
barcodeFormats
Limits
BarcodeScannerto the givenBarcodeFormatconstants. The platform detector is configured with only these symbologies, so it neither spends frame time on formats the application will never accept nor reports one of them by mistake -- which matters most for dense codes such as PDF417, where every frame counts. Analyzers other than the barcode scanner ignore it, as does a backend with no way to restrict its detector (it still reports every format).CodeScannerOptions.formats(String...)sets this for the scanner it opens, so aCodeScannercaller does not need both.- Parameters:
values- format constants; empty ornulldetects every format the backend supports- Returns:
- this options object
-
strictBarcodes
Makes a
BarcodeScannerreport a code only once two frames have read it identically. By default this applies to PDF417 codes in camera frames alone, and every other code, and any code in a still image, is reported as soon as it decodes;trueextends it to every symbology,falseturns it off for PDF417 as well.Turn this on for codes printed with little or no error correction. A PDF417 at error correction level 0 carries two check codewords, which is enough to "correct" one wrong codeword but not to notice when a blurred frame got several wrong: the decoder then repairs the frame into a different, valid-looking payload with a few wrong characters. That happens on a measurable share of frames, and differently on each, so two frames that agree byte for byte filter those reads out, at the cost of one more frame.
This is state kept by the scanner between calls to
VisionAnalyzer.process(VisionImage), which is what a camera pipeline (VisionCameraView,CodeScanner) does once per frame. A frame with no code keeps the pending read for up to 15 frames, and every code in a frame is checked against every code of the pending frame, so codes in view whose order changes between frames still confirm. With this set totruea single still image processed once reports nothing.- Parameters:
value- whether a code must be read identically twice- Returns:
- this options object
-
isStrictBarcodes
public boolean isStrictBarcodes()- Returns:
- whether every symbology must be read identically twice; see
isStrictBarcode(String)for the PDF417 default
-
isStrictBarcode
Whether a code of the given format must be read identically twice. UnlessstrictBarcodes(boolean)was called, that is true of PDF417 alone: it is the symbology printed at error correction level 0 (payment slips), where a blurred frame decodes into a plausible wrong payload on a large share of frames.- Parameters:
format- aBarcodeFormatconstant- Returns:
- whether that format is confirmed by a second frame
-
getBarcodeFormats
- Returns:
- defensive copy of the barcode formats to detect; empty detects every format
-
getBackend
- Returns:
- selected backend, never
null
-
getMinimumConfidence
public float getMinimumConfidence()- Returns:
- confidence threshold in the range 0..1
-
getMaximumResults
public int getMaximumResults()- Returns:
- non-negative result limit; zero means backend default/unlimited
-
getTextScript
- Returns:
- the selected writing system, or
nullfor the platform default
-