react-native-rectangle-doc-scanner 10.48.0 → 10.49.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.
@@ -471,8 +471,8 @@ class DocumentDetector {
471
471
  }
472
472
 
473
473
  /**
474
- * Evaluate rectangle quality in view coordinates (closer to iOS behavior).
475
- * Improved thresholds for better detection accuracy.
474
+ * Evaluate rectangle quality in view coordinates (iOS-like behavior).
475
+ * Focuses on rectangle size and angle quality.
476
476
  */
477
477
  fun evaluateRectangleQualityInView(
478
478
  rectangle: Rectangle,
@@ -484,6 +484,7 @@ class DocumentDetector {
484
484
  }
485
485
 
486
486
  val minDim = kotlin.math.min(viewWidth.toDouble(), viewHeight.toDouble())
487
+ val viewArea = viewWidth.toDouble() * viewHeight.toDouble()
487
488
 
488
489
  // Calculate actual edge lengths for better angle evaluation
489
490
  val topEdgeLength = distance(rectangle.topLeft, rectangle.topRight)
@@ -491,9 +492,26 @@ class DocumentDetector {
491
492
  val leftEdgeLength = distance(rectangle.topLeft, rectangle.bottomLeft)
492
493
  val rightEdgeLength = distance(rectangle.topRight, rectangle.bottomRight)
493
494
 
494
- // Use more lenient threshold: 12% of minimum dimension (reduced from 18%)
495
- // This allows for more realistic perspective angles
496
- val angleThreshold = max(80.0, minDim * 0.12)
495
+ // Calculate rectangle area (approximate using bounding box)
496
+ val rectWidth = max(topEdgeLength, bottomEdgeLength)
497
+ val rectHeight = max(leftEdgeLength, rightEdgeLength)
498
+ val rectArea = rectWidth * rectHeight
499
+
500
+ // Check if rectangle is too small (less than 15% of view area)
501
+ val areaRatio = rectArea / viewArea
502
+ if (areaRatio < 0.15) {
503
+ if (BuildConfig.DEBUG) {
504
+ Log.d(TAG, "[QUALITY] TOO_FAR: area=${String.format("%.1f", rectArea)}, ratio=${String.format("%.2f", areaRatio)}")
505
+ }
506
+ return RectangleQuality.TOO_FAR
507
+ }
508
+
509
+ // Check angle quality: edges should not be too skewed
510
+ // More lenient threshold: 20% of edge length
511
+ val topAngleThreshold = max(60.0, topEdgeLength * 0.20)
512
+ val bottomAngleThreshold = max(60.0, bottomEdgeLength * 0.20)
513
+ val leftAngleThreshold = max(60.0, leftEdgeLength * 0.20)
514
+ val rightAngleThreshold = max(60.0, rightEdgeLength * 0.20)
497
515
 
498
516
  val topYDiff = abs(rectangle.topRight.y - rectangle.topLeft.y)
499
517
  val bottomYDiff = abs(rectangle.bottomLeft.y - rectangle.bottomRight.y)
@@ -501,30 +519,35 @@ class DocumentDetector {
501
519
  val rightXDiff = abs(rectangle.topRight.x - rectangle.bottomRight.x)
502
520
 
503
521
  // Check if edges are too skewed (perspective too extreme)
504
- if (topYDiff > angleThreshold || bottomYDiff > angleThreshold ||
505
- leftXDiff > angleThreshold || rightXDiff > angleThreshold) {
522
+ if (topYDiff > topAngleThreshold ||
523
+ bottomYDiff > bottomAngleThreshold ||
524
+ leftXDiff > leftAngleThreshold ||
525
+ rightXDiff > rightAngleThreshold) {
526
+ if (BuildConfig.DEBUG) {
527
+ Log.d(TAG, "[QUALITY] BAD_ANGLE (skew): topY=$topYDiff>${String.format("%.1f", topAngleThreshold)}, " +
528
+ "bottomY=$bottomYDiff>${String.format("%.1f", bottomAngleThreshold)}, " +
529
+ "leftX=$leftXDiff>${String.format("%.1f", leftAngleThreshold)}, " +
530
+ "rightX=$rightXDiff>${String.format("%.1f", rightAngleThreshold)}")
531
+ }
506
532
  return RectangleQuality.BAD_ANGLE
507
533
  }
508
534
 
509
- // Additional check: opposite edges should be somewhat similar in length
510
- // Allow up to 60% difference (more lenient for perspective)
535
+ // Check opposite edge ratio (perspective check)
536
+ // More lenient: allow 3x difference
511
537
  val topBottomRatio = if (bottomEdgeLength > 0) topEdgeLength / bottomEdgeLength else 0.0
512
538
  val leftRightRatio = if (rightEdgeLength > 0) leftEdgeLength / rightEdgeLength else 0.0
513
- if (topBottomRatio < 0.4 || topBottomRatio > 2.5 ||
514
- leftRightRatio < 0.4 || leftRightRatio > 2.5) {
539
+ if (topBottomRatio < 0.33 || topBottomRatio > 3.0 ||
540
+ leftRightRatio < 0.33 || leftRightRatio > 3.0) {
541
+ if (BuildConfig.DEBUG) {
542
+ Log.d(TAG, "[QUALITY] BAD_ANGLE (ratio): topBottom=${String.format("%.2f", topBottomRatio)}, " +
543
+ "leftRight=${String.format("%.2f", leftRightRatio)}")
544
+ }
515
545
  return RectangleQuality.BAD_ANGLE
516
546
  }
517
547
 
518
- // More lenient margin check: 8% of minimum dimension (increased from 5%)
519
- val margin = max(80.0, minDim * 0.08)
520
- if (rectangle.topLeft.y > margin ||
521
- rectangle.topRight.y > margin ||
522
- rectangle.bottomLeft.y < (viewHeight - margin) ||
523
- rectangle.bottomRight.y < (viewHeight - margin)
524
- ) {
525
- return RectangleQuality.TOO_FAR
548
+ if (BuildConfig.DEBUG) {
549
+ Log.d(TAG, "[QUALITY] GOOD: area=${String.format("%.1f", rectArea)}, ratio=${String.format("%.2f", areaRatio)}")
526
550
  }
527
-
528
551
  return RectangleQuality.GOOD
529
552
  }
530
553
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "10.48.0",
3
+ "version": "10.49.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",