react-native-rectangle-doc-scanner 13.5.0 → 13.7.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.
|
@@ -210,10 +210,10 @@ class DocumentDetector {
|
|
|
210
210
|
|
|
211
211
|
val median = computeMedian(blurredMat)
|
|
212
212
|
val sigma = 0.33
|
|
213
|
-
//
|
|
214
|
-
//
|
|
215
|
-
val cannyLow = max(50.0, (1.0 - sigma) * median).coerceAtLeast(
|
|
216
|
-
val cannyHigh = max(150.0, (1.0 + sigma) * median).coerceAtLeast(
|
|
213
|
+
// Balanced thresholds for high-res (1280x960)
|
|
214
|
+
// Lower than before to detect document edges, but higher than default to reduce noise
|
|
215
|
+
val cannyLow = max(50.0, (1.0 - sigma) * median).coerceAtLeast(60.0)
|
|
216
|
+
val cannyHigh = max(150.0, (1.0 + sigma) * median).coerceAtLeast(120.0)
|
|
217
217
|
|
|
218
218
|
// Apply Canny edge detection with adaptive thresholds for better corner detection.
|
|
219
219
|
Imgproc.Canny(blurredMat, cannyMat, cannyLow, cannyHigh)
|
|
@@ -261,13 +261,17 @@ class DocumentDetector {
|
|
|
261
261
|
|
|
262
262
|
var largestRectangle: Rectangle? = null
|
|
263
263
|
var bestScore = 0.0
|
|
264
|
-
val
|
|
264
|
+
val imageArea = (srcMat.rows() * srcMat.cols()).toDouble()
|
|
265
|
+
// Min: 2% of image (documents should be visible)
|
|
266
|
+
// Max: 85% of image (avoid detecting screen borders)
|
|
267
|
+
val minArea = max(350.0, imageArea * 0.02)
|
|
268
|
+
val maxArea = imageArea * 0.85
|
|
265
269
|
|
|
266
270
|
debugStats.contours = contours.size
|
|
267
271
|
|
|
268
272
|
for (contour in contours) {
|
|
269
273
|
val contourArea = Imgproc.contourArea(contour)
|
|
270
|
-
if (contourArea < minArea) continue
|
|
274
|
+
if (contourArea < minArea || contourArea > maxArea) continue
|
|
271
275
|
|
|
272
276
|
val approx = MatOfPoint2f()
|
|
273
277
|
val contour2f = MatOfPoint2f(*contour.toArray())
|
|
@@ -291,7 +295,8 @@ class DocumentDetector {
|
|
|
291
295
|
val rect = Imgproc.minAreaRect(MatOfPoint2f(*points))
|
|
292
296
|
val rectArea = rect.size.area()
|
|
293
297
|
val rectangularity = if (rectArea > 1.0) contourArea / rectArea else 0.0
|
|
294
|
-
|
|
298
|
+
// Stricter rectangularity check (0.7 = more rectangular shapes only)
|
|
299
|
+
if (rectangularity >= 0.7 && isCandidateValid(ordered, srcMat)) {
|
|
295
300
|
debugStats.candidates += 1
|
|
296
301
|
val score = contourArea * rectangularity
|
|
297
302
|
if (score > bestScore) {
|
|
@@ -439,29 +444,6 @@ class DocumentDetector {
|
|
|
439
444
|
return false
|
|
440
445
|
}
|
|
441
446
|
|
|
442
|
-
// TEMPORARILY DISABLED: Enhanced filters were too strict
|
|
443
|
-
// TODO: Re-enable with more lenient thresholds after testing
|
|
444
|
-
/*
|
|
445
|
-
// Enhanced validation: Check corner angles (should be close to 90°)
|
|
446
|
-
if (!hasValidCornerAngles(rectangle)) {
|
|
447
|
-
return false
|
|
448
|
-
}
|
|
449
|
-
|
|
450
|
-
// Enhanced validation: Check edge straightness
|
|
451
|
-
if (!hasValidEdgeStraightness(rectangle, srcMat)) {
|
|
452
|
-
return false
|
|
453
|
-
}
|
|
454
|
-
|
|
455
|
-
// Enhanced validation: Check margin from view edges (avoid detecting screen borders)
|
|
456
|
-
val margin = minDim * 0.03
|
|
457
|
-
if (rectangle.topLeft.x < margin || rectangle.topLeft.y < margin ||
|
|
458
|
-
rectangle.topRight.x > srcMat.cols() - margin || rectangle.topRight.y < margin ||
|
|
459
|
-
rectangle.bottomLeft.x < margin || rectangle.bottomLeft.y > srcMat.rows() - margin ||
|
|
460
|
-
rectangle.bottomRight.x > srcMat.cols() - margin || rectangle.bottomRight.y > srcMat.rows() - margin) {
|
|
461
|
-
return false
|
|
462
|
-
}
|
|
463
|
-
*/
|
|
464
|
-
|
|
465
447
|
return true
|
|
466
448
|
}
|
|
467
449
|
|