react-native-rectangle-doc-scanner 10.47.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.
|
@@ -547,8 +547,16 @@ class CameraController(
|
|
|
547
547
|
|
|
548
548
|
// For sensor=0 (tablet landscape), we need to manually rotate the buffer
|
|
549
549
|
// CameraX only handles rotation automatically for sensor=90 (phone portrait)
|
|
550
|
+
// Important: For sensor=0, we need to rotate in the OPPOSITE direction
|
|
551
|
+
// When display is 90° (portrait), we need to rotate -90° (270°) to compensate
|
|
550
552
|
if (sensorOrientation == 0 && displayRotationDegrees != 0) {
|
|
551
|
-
|
|
553
|
+
val rotationDegrees = when (displayRotationDegrees) {
|
|
554
|
+
90 -> -90f // Display 90° → Rotate -90° (counter-clockwise)
|
|
555
|
+
180 -> -180f
|
|
556
|
+
270 -> -270f // Or +90f
|
|
557
|
+
else -> 0f
|
|
558
|
+
}
|
|
559
|
+
matrix.postRotate(rotationDegrees, centerX, centerY)
|
|
552
560
|
}
|
|
553
561
|
|
|
554
562
|
// Calculate rotated buffer dimensions
|
|
@@ -471,8 +471,8 @@ class DocumentDetector {
|
|
|
471
471
|
}
|
|
472
472
|
|
|
473
473
|
/**
|
|
474
|
-
* Evaluate rectangle quality in view coordinates (
|
|
475
|
-
*
|
|
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
|
-
//
|
|
495
|
-
|
|
496
|
-
val
|
|
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 >
|
|
505
|
-
|
|
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
|
-
//
|
|
510
|
-
//
|
|
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.
|
|
514
|
-
leftRightRatio < 0.
|
|
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
|
-
|
|
519
|
-
|
|
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