Committed by
GitHub
Merge pull request #839 from pgeof/master
fix: with the "noDuplicates", the same code is no longer detected after stopping and restarting the scanner
Showing
2 changed files
with
7 additions
and
4 deletions
| @@ -69,7 +69,7 @@ class MobileScanner( | @@ -69,7 +69,7 @@ class MobileScanner( | ||
| 69 | scanner.process(inputImage) | 69 | scanner.process(inputImage) |
| 70 | .addOnSuccessListener { barcodes -> | 70 | .addOnSuccessListener { barcodes -> |
| 71 | if (detectionSpeed == DetectionSpeed.NO_DUPLICATES) { | 71 | if (detectionSpeed == DetectionSpeed.NO_DUPLICATES) { |
| 72 | - val newScannedBarcodes = barcodes.map { barcode -> barcode.rawValue } | 72 | + val newScannedBarcodes = barcodes.mapNotNull({ barcode -> barcode.rawValue }).sorted() |
| 73 | if (newScannedBarcodes == lastScanned) { | 73 | if (newScannedBarcodes == lastScanned) { |
| 74 | // New scanned is duplicate, returning | 74 | // New scanned is duplicate, returning |
| 75 | return@addOnSuccessListener | 75 | return@addOnSuccessListener |
| @@ -226,6 +226,7 @@ class MobileScanner( | @@ -226,6 +226,7 @@ class MobileScanner( | ||
| 226 | return | 226 | return |
| 227 | } | 227 | } |
| 228 | 228 | ||
| 229 | + lastScanned = null | ||
| 229 | scanner = if (barcodeScannerOptions != null) { | 230 | scanner = if (barcodeScannerOptions != null) { |
| 230 | BarcodeScanning.getClient(barcodeScannerOptions) | 231 | BarcodeScanning.getClient(barcodeScannerOptions) |
| 231 | } else { | 232 | } else { |
| @@ -117,12 +117,13 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -117,12 +117,13 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 117 | imagesCurrentlyBeingProcessed = false | 117 | imagesCurrentlyBeingProcessed = false |
| 118 | 118 | ||
| 119 | if (detectionSpeed == DetectionSpeed.noDuplicates) { | 119 | if (detectionSpeed == DetectionSpeed.noDuplicates) { |
| 120 | - let newScannedBarcodes = barcodes?.map { barcode in | 120 | + let newScannedBarcodes = barcodes?.compactMap({ barcode in |
| 121 | return barcode.rawValue | 121 | return barcode.rawValue |
| 122 | - } | 122 | + }).sorted() |
| 123 | + | ||
| 123 | if (error == nil && barcodesString != nil && newScannedBarcodes != nil && barcodesString!.elementsEqual(newScannedBarcodes!)) { | 124 | if (error == nil && barcodesString != nil && newScannedBarcodes != nil && barcodesString!.elementsEqual(newScannedBarcodes!)) { |
| 124 | return | 125 | return |
| 125 | - } else { | 126 | + } else if (newScannedBarcodes?.isEmpty == false) { |
| 126 | barcodesString = newScannedBarcodes | 127 | barcodesString = newScannedBarcodes |
| 127 | } | 128 | } |
| 128 | } | 129 | } |
| @@ -139,6 +140,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | @@ -139,6 +140,7 @@ public class MobileScanner: NSObject, AVCaptureVideoDataOutputSampleBufferDelega | ||
| 139 | throw MobileScannerError.alreadyStarted | 140 | throw MobileScannerError.alreadyStarted |
| 140 | } | 141 | } |
| 141 | 142 | ||
| 143 | + barcodesString = nil | ||
| 142 | scanner = barcodeScannerOptions != nil ? BarcodeScanner.barcodeScanner(options: barcodeScannerOptions!) : BarcodeScanner.barcodeScanner() | 144 | scanner = barcodeScannerOptions != nil ? BarcodeScanner.barcodeScanner(options: barcodeScannerOptions!) : BarcodeScanner.barcodeScanner() |
| 143 | captureSession = AVCaptureSession() | 145 | captureSession = AVCaptureSession() |
| 144 | textureId = registry?.register(self) | 146 | textureId = registry?.register(self) |
-
Please register or login to post a comment