@@ -30,50 +30,25 @@ The following example reads an EAN-13 barcode, disables incorrect barcode result
3030``` java
3131String imagePath = " rv_ean13_valid.png" ;
3232
33- BarCodeReader reader = new BarCodeReader (
34- imagePath,
35- DecodeType . EAN_13
36- );
33+ BarCodeReader reader = new BarCodeReader (imagePath, DecodeType . EAN_13 );
34+ reader. getQualitySettings(). setAllowIncorrectBarcodes(false );
3735
38- reader. getQualitySettings()
39- .setAllowIncorrectBarcodes(false );
40-
41- BarCodeResult [] results =
42- reader. readBarCodes();
36+ BarCodeResult [] results = reader. readBarCodes();
4337
4438if (results. length == 0 ) {
45- throw new IllegalStateException (
46- " Expected a valid EAN-13 barcode."
47- );
39+ throw new IllegalStateException (" Expected a valid EAN-13 barcode." );
4840}
4941
5042BarCodeResult result = results[0 ];
43+ BarCodeExtendedParameters extended = result. getExtended();
5144
52- BarCodeExtendedParameters extended =
53- result. getExtended();
54-
55- if (extended == null
56- || extended. getOneD() == null ) {
57- throw new IllegalStateException (
58- " One-dimensional extended parameters "
59- + " are not available."
60- );
45+ if (extended == null || extended. getOneD() == null ) {
46+ throw new IllegalStateException (" One-dimensional extended parameters are not available." );
6147}
6248
63- System . out. println(
64- " Recognized text: "
65- + result. getCodeText()
66- );
67-
68- System . out. println(
69- " Confidence: "
70- + result. getConfidence()
71- );
72-
73- System . out. println(
74- " Checksum: "
75- + extended. getOneD(). getCheckSum()
76- );
49+ System . out. println(" Recognized text: " + result. getCodeText());
50+ System . out. println(" Confidence: " + result. getConfidence());
51+ System . out. println(" Checksum: " + extended. getOneD(). getCheckSum());
7752```
7853
7954` setAllowIncorrectBarcodes(false) ` requests stricter filtering of incorrect recognition candidates. If the barcode is severely damaged, the reader may return no result rather than expose an unreliable candidate.
@@ -87,37 +62,16 @@ For damaged input, you can compare recognition with incorrect barcode results di
8762``` java
8863String imagePath = " rv_code39_damaged.png" ;
8964
90- BarCodeReader strictReader = new BarCodeReader (
91- imagePath,
92- DecodeType . CODE_39
93- );
94-
95- strictReader. getQualitySettings()
96- .setAllowIncorrectBarcodes(false );
97-
98- BarCodeResult [] strictResults =
99- strictReader. readBarCodes();
65+ BarCodeReader strictReader = new BarCodeReader (imagePath, DecodeType . CODE_39 );
66+ strictReader. getQualitySettings(). setAllowIncorrectBarcodes(false );
67+ BarCodeResult [] strictResults = strictReader. readBarCodes();
10068
101- BarCodeReader lenientReader = new BarCodeReader (
102- imagePath,
103- DecodeType . CODE_39
104- );
69+ BarCodeReader lenientReader = new BarCodeReader (imagePath, DecodeType . CODE_39 );
70+ lenientReader. getQualitySettings(). setAllowIncorrectBarcodes(true );
71+ BarCodeResult [] lenientResults = lenientReader. readBarCodes();
10572
106- lenientReader. getQualitySettings()
107- .setAllowIncorrectBarcodes(true );
108-
109- BarCodeResult [] lenientResults =
110- lenientReader. readBarCodes();
111-
112- System . out. println(
113- " Strict count: "
114- + strictResults. length
115- );
116-
117- System . out. println(
118- " Lenient count: "
119- + lenientResults. length
120- );
73+ System . out. println(" Strict count: " + strictResults. length);
74+ System . out. println(" Lenient count: " + lenientResults. length);
12175```
12276
12377Allowing incorrect results can expose additional candidates for diagnostics. It does not mean that every returned candidate should be accepted.
@@ -141,53 +95,23 @@ The following example compares a clean QR image with a noisy version of the same
14195String cleanImagePath = " rv_qr_clean.png" ;
14296String noisyImagePath = " rv_qr_noisy.png" ;
14397
144- BarCodeReader cleanReader = new BarCodeReader (
145- cleanImagePath,
146- DecodeType . QR
147- );
148-
149- cleanReader. setQualitySettings(
150- QualitySettings . getHighQuality()
151- );
152-
153- BarCodeResult [] cleanResults =
154- cleanReader. readBarCodes();
98+ BarCodeReader cleanReader = new BarCodeReader (cleanImagePath, DecodeType . QR );
99+ cleanReader. setQualitySettings(QualitySettings . getHighQuality());
100+ BarCodeResult [] cleanResults = cleanReader. readBarCodes();
155101
156- BarCodeReader noisyReader = new BarCodeReader (
157- noisyImagePath,
158- DecodeType . QR
159- );
102+ BarCodeReader noisyReader = new BarCodeReader (noisyImagePath, DecodeType . QR );
103+ noisyReader. setQualitySettings(QualitySettings . getHighQuality());
104+ BarCodeResult [] noisyResults = noisyReader. readBarCodes();
160105
161- noisyReader. setQualitySettings(
162- QualitySettings . getHighQuality()
163- );
164-
165- BarCodeResult [] noisyResults =
166- noisyReader. readBarCodes();
167-
168- if (cleanResults. length == 0
169- || noisyResults. length == 0 ) {
170- throw new IllegalStateException (
171- " Both QR images must be recognized "
172- + " for confidence comparison."
173- );
106+ if (cleanResults. length == 0 || noisyResults. length == 0 ) {
107+ throw new IllegalStateException (" Both QR images must be recognized for confidence comparison." );
174108}
175109
176- double cleanConfidence =
177- cleanResults[0 ]. getConfidence();
178-
179- double noisyConfidence =
180- noisyResults[0 ]. getConfidence();
110+ double cleanConfidence = cleanResults[0 ]. getConfidence();
111+ double noisyConfidence = noisyResults[0 ]. getConfidence();
181112
182- System . out. println(
183- " Clean confidence: "
184- + cleanConfidence
185- );
186-
187- System . out. println(
188- " Noisy confidence: "
189- + noisyConfidence
190- );
113+ System . out. println(" Clean confidence: " + cleanConfidence);
114+ System . out. println(" Noisy confidence: " + noisyConfidence);
191115```
192116
193117Confidence is a heuristic value, not a calibrated probability that the result is correct.
@@ -214,36 +138,16 @@ The following example compares both presets on a small Code 128 image.
214138``` java
215139String imagePath = " rv_c128_small.png" ;
216140
217- BarCodeReader highPerformanceReader = new BarCodeReader (
218- imagePath,
219- DecodeType . CODE_128
220- );
221-
141+ BarCodeReader highPerformanceReader = new BarCodeReader (imagePath, DecodeType . CODE_128 );
222142highPerformanceReader. setQualitySettings(QualitySettings . getHighPerformance());
143+ BarCodeResult [] highPerformanceResults = highPerformanceReader. readBarCodes();
223144
224- BarCodeResult [] highPerformanceResults =
225- highPerformanceReader. readBarCodes();
226-
227- BarCodeReader highQualityReader =
228- new BarCodeReader (
229- imagePath,
230- DecodeType . CODE_128
231- );
232-
145+ BarCodeReader highQualityReader = new BarCodeReader (imagePath, DecodeType . CODE_128 );
233146highQualityReader. setQualitySettings(QualitySettings . getHighQuality());
147+ BarCodeResult [] highQualityResults = highQualityReader. readBarCodes();
234148
235- BarCodeResult [] highQualityResults =
236- highQualityReader. readBarCodes();
237-
238- System . out. println(
239- " HighPerformance count: "
240- + highPerformanceResults. length
241- );
242-
243- System . out. println(
244- " HighQuality count: "
245- + highQualityResults. length
246- );
149+ System . out. println(" HighPerformance count: " + highPerformanceResults. length);
150+ System . out. println(" HighQuality count: " + highQualityResults. length);
247151```
248152
249153Different presets can return different candidate counts for the same image. For example, ` HighPerformance ` may return no result while ` HighQuality ` detects a candidate.
@@ -272,17 +176,11 @@ A result should normally be accepted only after its type and decoded value have
272176BarCodeResult result = results[0 ];
273177
274178if (! result. getCodeType(). equals(DecodeType . CODE_128 )) {
275- throw new IllegalStateException (
276- " Unexpected barcode type: "
277- + result. getCodeType()
278- );
279- }
179+ throw new IllegalStateException (" Unexpected barcode type: " + result. getCodeType());
180+ }
280181
281- if (! result. getCodeText(). matches(" [A-Z0-9-]+" )) {
282- throw new IllegalStateException (
283- " Recognized text does not match "
284- + " the expected format."
285- );
182+ if (! result. getCodeText(). matches(" [A-Z0-9-]+" )) {
183+ throw new IllegalStateException (" Recognized text does not match the expected format." );
286184}
287185```
288186
0 commit comments