react-native-rectangle-doc-scanner 13.3.0 → 13.4.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.
package/android/src/camera2/kotlin/com/reactnativerectangledocscanner/DocumentScannerView.kt
CHANGED
|
@@ -151,10 +151,25 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
151
151
|
private fun layoutPreviewAndOverlay(viewWidth: Int, viewHeight: Int) {
|
|
152
152
|
if (viewWidth <= 0 || viewHeight <= 0) return
|
|
153
153
|
|
|
154
|
-
//
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
154
|
+
// Check if device is tablet (screen width >= 600dp)
|
|
155
|
+
val isTablet = (viewWidth / resources.displayMetrics.density) >= 600
|
|
156
|
+
|
|
157
|
+
if (isTablet) {
|
|
158
|
+
// Tablet: Fill entire view to prevent squished appearance
|
|
159
|
+
previewView.layout(0, 0, viewWidth, viewHeight)
|
|
160
|
+
overlayView.layout(0, 0, viewWidth, viewHeight)
|
|
161
|
+
} else {
|
|
162
|
+
// Phone: Use 4:3 aspect ratio with letterboxing
|
|
163
|
+
val targetAspectRatio = 3f / 4f // width/height
|
|
164
|
+
val targetWidth = viewWidth
|
|
165
|
+
val targetHeight = (viewWidth / targetAspectRatio).toInt()
|
|
166
|
+
|
|
167
|
+
val top = (viewHeight - targetHeight) / 2
|
|
168
|
+
val bottom = top + targetHeight
|
|
169
|
+
|
|
170
|
+
previewView.layout(0, top, viewWidth, bottom)
|
|
171
|
+
overlayView.layout(0, top, viewWidth, bottom)
|
|
172
|
+
}
|
|
158
173
|
}
|
|
159
174
|
|
|
160
175
|
private fun initializeCameraWhenReady() {
|
|
@@ -438,17 +438,20 @@ class DocumentDetector {
|
|
|
438
438
|
}
|
|
439
439
|
|
|
440
440
|
// Enhanced validation: Check corner angles (should be close to 90°)
|
|
441
|
+
// Made more lenient: 50°-130° (was 60°-120°)
|
|
441
442
|
if (!hasValidCornerAngles(rectangle)) {
|
|
442
443
|
return false
|
|
443
444
|
}
|
|
444
445
|
|
|
445
446
|
// Enhanced validation: Check edge straightness
|
|
447
|
+
// Made more lenient: 20° tolerance (was 15°)
|
|
446
448
|
if (!hasValidEdgeStraightness(rectangle, srcMat)) {
|
|
447
449
|
return false
|
|
448
450
|
}
|
|
449
451
|
|
|
450
452
|
// Enhanced validation: Check margin from view edges (avoid detecting screen borders)
|
|
451
|
-
|
|
453
|
+
// Made more lenient: 3% margin (was 5%)
|
|
454
|
+
val margin = minDim * 0.03
|
|
452
455
|
if (rectangle.topLeft.x < margin || rectangle.topLeft.y < margin ||
|
|
453
456
|
rectangle.topRight.x > srcMat.cols() - margin || rectangle.topRight.y < margin ||
|
|
454
457
|
rectangle.bottomLeft.x < margin || rectangle.bottomLeft.y > srcMat.rows() - margin ||
|
|
@@ -484,9 +487,9 @@ class DocumentDetector {
|
|
|
484
487
|
val angleBL = angleAt(rectangle.topLeft, rectangle.bottomLeft, rectangle.bottomRight)
|
|
485
488
|
val angleBR = angleAt(rectangle.topRight, rectangle.bottomRight, rectangle.bottomLeft)
|
|
486
489
|
|
|
487
|
-
// All angles should be within
|
|
488
|
-
return angleTL in
|
|
489
|
-
angleBL in
|
|
490
|
+
// All angles should be within 50°-130° (allow ±40° from 90°, more lenient)
|
|
491
|
+
return angleTL in 50.0..130.0 && angleTR in 50.0..130.0 &&
|
|
492
|
+
angleBL in 50.0..130.0 && angleBR in 50.0..130.0
|
|
490
493
|
}
|
|
491
494
|
|
|
492
495
|
/**
|
|
@@ -512,8 +515,8 @@ class DocumentDetector {
|
|
|
512
515
|
val dot = (dx1 * dx2 + dy1 * dy2) / (len1 * len2)
|
|
513
516
|
val angleDiff = Math.toDegrees(kotlin.math.acos(dot.coerceIn(-1.0, 1.0)))
|
|
514
517
|
|
|
515
|
-
// Parallel lines should have angle diff close to 0° or 180°
|
|
516
|
-
return angleDiff <
|
|
518
|
+
// Parallel lines should have angle diff close to 0° or 180° (more lenient: 20° tolerance)
|
|
519
|
+
return angleDiff < 20.0 || angleDiff > 160.0
|
|
517
520
|
}
|
|
518
521
|
|
|
519
522
|
// Check top vs bottom edges
|