react-native-rectangle-doc-scanner 13.3.0 → 13.5.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.
@@ -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
- // Fill entire view to prevent squished appearance on tablets
155
- // CameraX will handle aspect ratio via center-crop in updateTextureViewTransform
156
- previewView.layout(0, 0, viewWidth, viewHeight)
157
- overlayView.layout(0, 0, viewWidth, viewHeight)
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() {
@@ -210,8 +210,10 @@ class DocumentDetector {
210
210
 
211
211
  val median = computeMedian(blurredMat)
212
212
  val sigma = 0.33
213
- val cannyLow = max(25.0, (1.0 - sigma) * median)
214
- val cannyHigh = max(80.0, (1.0 + sigma) * median)
213
+ // Increased thresholds for high-res (1280x960) to reduce noise
214
+ // This makes edge detection less sensitive, focusing on strong edges only
215
+ val cannyLow = max(50.0, (1.0 - sigma) * median).coerceAtLeast(100.0)
216
+ val cannyHigh = max(150.0, (1.0 + sigma) * median).coerceAtLeast(200.0)
215
217
 
216
218
  // Apply Canny edge detection with adaptive thresholds for better corner detection.
217
219
  Imgproc.Canny(blurredMat, cannyMat, cannyLow, cannyHigh)
@@ -437,6 +439,9 @@ class DocumentDetector {
437
439
  return false
438
440
  }
439
441
 
442
+ // TEMPORARILY DISABLED: Enhanced filters were too strict
443
+ // TODO: Re-enable with more lenient thresholds after testing
444
+ /*
440
445
  // Enhanced validation: Check corner angles (should be close to 90°)
441
446
  if (!hasValidCornerAngles(rectangle)) {
442
447
  return false
@@ -448,13 +453,14 @@ class DocumentDetector {
448
453
  }
449
454
 
450
455
  // Enhanced validation: Check margin from view edges (avoid detecting screen borders)
451
- val margin = minDim * 0.05 // 5% margin
456
+ val margin = minDim * 0.03
452
457
  if (rectangle.topLeft.x < margin || rectangle.topLeft.y < margin ||
453
458
  rectangle.topRight.x > srcMat.cols() - margin || rectangle.topRight.y < margin ||
454
459
  rectangle.bottomLeft.x < margin || rectangle.bottomLeft.y > srcMat.rows() - margin ||
455
460
  rectangle.bottomRight.x > srcMat.cols() - margin || rectangle.bottomRight.y > srcMat.rows() - margin) {
456
461
  return false
457
462
  }
463
+ */
458
464
 
459
465
  return true
460
466
  }
@@ -484,9 +490,9 @@ class DocumentDetector {
484
490
  val angleBL = angleAt(rectangle.topLeft, rectangle.bottomLeft, rectangle.bottomRight)
485
491
  val angleBR = angleAt(rectangle.topRight, rectangle.bottomRight, rectangle.bottomLeft)
486
492
 
487
- // All angles should be within 60°-120° (allow ±30° from 90°)
488
- return angleTL in 60.0..120.0 && angleTR in 60.0..120.0 &&
489
- angleBL in 60.0..120.0 && angleBR in 60.0..120.0
493
+ // All angles should be within 50°-130° (allow ±40° from 90°, more lenient)
494
+ return angleTL in 50.0..130.0 && angleTR in 50.0..130.0 &&
495
+ angleBL in 50.0..130.0 && angleBR in 50.0..130.0
490
496
  }
491
497
 
492
498
  /**
@@ -512,8 +518,8 @@ class DocumentDetector {
512
518
  val dot = (dx1 * dx2 + dy1 * dy2) / (len1 * len2)
513
519
  val angleDiff = Math.toDegrees(kotlin.math.acos(dot.coerceIn(-1.0, 1.0)))
514
520
 
515
- // Parallel lines should have angle diff close to 0° or 180°
516
- return angleDiff < 15.0 || angleDiff > 165.0
521
+ // Parallel lines should have angle diff close to 0° or 180° (more lenient: 20° tolerance)
522
+ return angleDiff < 20.0 || angleDiff > 160.0
517
523
  }
518
524
 
519
525
  // Check top vs bottom edges
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "13.3.0",
3
+ "version": "13.5.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",