react-native-rectangle-doc-scanner 1.12.0 → 1.13.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.
@@ -226,15 +226,23 @@ class RNRDocScannerView: UIView, AVCaptureVideoDataOutputSampleBufferDelegate, A
226
226
  let request = VNDetectRectanglesRequest(completionHandler: requestHandler)
227
227
 
228
228
  request.maximumObservations = 3
229
- request.minimumConfidence = 0.55
230
- request.minimumAspectRatio = 0.1
231
- request.maximumAspectRatio = 2.0
229
+ request.minimumConfidence = 0.65
230
+ request.minimumAspectRatio = 0.12
231
+ request.maximumAspectRatio = 1.9
232
232
  request.minimumSize = 0.05
233
233
  if #available(iOS 13.0, *) {
234
- request.quadratureTolerance = 20
234
+ request.quadratureTolerance = 18
235
235
  }
236
236
 
237
- let handler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: orientation, options: [:])
237
+ var processedImage = CIImage(cvPixelBuffer: pixelBuffer)
238
+ processedImage = processedImage.applyingFilter("CIColorControls", parameters: [
239
+ kCIInputContrastKey: 1.35,
240
+ kCIInputBrightnessKey: 0.02,
241
+ kCIInputSaturationKey: 1.05,
242
+ ])
243
+ processedImage = processedImage.applyingFilter("CISharpenLuminance", parameters: [kCIInputSharpnessKey: 0.5])
244
+
245
+ let handler = VNImageRequestHandler(ciImage: processedImage, orientation: orientation, options: [:])
238
246
  do {
239
247
  try handler.perform([request])
240
248
  } catch {
@@ -339,7 +347,7 @@ class RNRDocScannerView: UIView, AVCaptureVideoDataOutputSampleBufferDelegate, A
339
347
  let points: [CGPoint]
340
348
  if let previous = self.smoothedOverlayPoints, previous.count == 4 {
341
349
  points = zip(previous, orderedPoints).map { prev, next in
342
- CGPoint(x: prev.x * 0.75 + next.x * 0.25, y: prev.y * 0.75 + next.y * 0.25)
350
+ CGPoint(x: prev.x * 0.7 + next.x * 0.3, y: prev.y * 0.7 + next.y * 0.3)
343
351
  }
344
352
  } else {
345
353
  points = orderedPoints
@@ -421,7 +429,19 @@ class RNRDocScannerView: UIView, AVCaptureVideoDataOutputSampleBufferDelegate, A
421
429
  }
422
430
  }
423
431
 
424
- return [topLeft, topRight, bottomRight, bottomLeft]
432
+ var ordered = [topLeft, topRight, bottomRight, bottomLeft]
433
+ if cross(ordered[0], ordered[1], ordered[2]) < 0 {
434
+ ordered = [topLeft, bottomLeft, bottomRight, topRight]
435
+ }
436
+ return ordered
437
+ }
438
+
439
+ private func cross(_ a: CGPoint, _ b: CGPoint, _ c: CGPoint) -> CGFloat {
440
+ let abx = b.x - a.x
441
+ let aby = b.y - a.y
442
+ let acx = c.x - a.x
443
+ let acy = c.y - a.y
444
+ return abx * acy - aby * acx
425
445
  }
426
446
 
427
447
  // MARK: - Capture
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "1.12.0",
3
+ "version": "1.13.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",