react-native-rectangle-doc-scanner 1.4.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -165,36 +165,41 @@ class RNRDocScannerView: UIView, AVCaptureVideoDataOutputSampleBufferDelegate, A
|
|
|
165
165
|
isProcessingFrame = false
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if let error {
|
|
172
|
-
NSLog("[RNRDocScanner] detection error: \(error)")
|
|
173
|
-
self.lastObservation = nil
|
|
174
|
-
self.handleDetectedRectangle(nil, frameSize: frameSize)
|
|
175
|
-
return
|
|
176
|
-
}
|
|
168
|
+
let requestHandler: VNRequestCompletionHandler = { [weak self] request, error in
|
|
169
|
+
guard let self = self else { return }
|
|
177
170
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
171
|
+
if let error = error {
|
|
172
|
+
NSLog("[RNRDocScanner] detection error: \(error)")
|
|
173
|
+
self.lastObservation = nil
|
|
174
|
+
self.handleDetectedRectangle(nil, frameSize: frameSize)
|
|
175
|
+
return
|
|
176
|
+
}
|
|
183
177
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
178
|
+
guard let observations = request.results as? [VNRectangleObservation], !observations.isEmpty else {
|
|
179
|
+
self.lastObservation = nil
|
|
180
|
+
self.handleDetectedRectangle(nil, frameSize: frameSize)
|
|
181
|
+
return
|
|
182
|
+
}
|
|
187
183
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
self.
|
|
184
|
+
let weighted: [VNRectangleObservation] = observations.sorted { (lhs: VNRectangleObservation, rhs: VNRectangleObservation) -> Bool in
|
|
185
|
+
let lhsScore: CGFloat = CGFloat(lhs.confidence) * lhs.boundingBox.area
|
|
186
|
+
let rhsScore: CGFloat = CGFloat(rhs.confidence) * rhs.boundingBox.area
|
|
187
|
+
return lhsScore > rhsScore
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
guard let best = weighted.first else {
|
|
191
|
+
self.lastObservation = nil
|
|
192
|
+
self.handleDetectedRectangle(nil, frameSize: frameSize)
|
|
193
|
+
return
|
|
196
194
|
}
|
|
197
195
|
|
|
196
|
+
self.lastObservation = best
|
|
197
|
+
self.missedDetectionFrames = 0
|
|
198
|
+
self.handleDetectedRectangle(best, frameSize: frameSize)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
let request = VNDetectRectanglesRequest(completionHandler: requestHandler)
|
|
202
|
+
|
|
198
203
|
request.maximumObservations = 2
|
|
199
204
|
request.minimumConfidence = 0.4
|
|
200
205
|
request.minimumAspectRatio = 0.08
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
#import <React/RCTUIManager.h>
|
|
3
3
|
#import <React/RCTViewManager.h>
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
// Swift bridging header not needed with @objc annotations in Swift files
|
|
6
|
+
// #import "react-native-rectangle-doc-scanner-Swift.h"
|
|
6
7
|
|
|
7
8
|
@interface RCT_EXTERN_MODULE(RNRDocScannerViewManager, RCTViewManager)
|
|
8
9
|
RCT_EXPORT_VIEW_PROPERTY(detectionCountBeforeCapture, NSNumber)
|