react-native-rectangle-doc-scanner 13.6.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.
|
@@ -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,16 +444,6 @@ class DocumentDetector {
|
|
|
439
444
|
return false
|
|
440
445
|
}
|
|
441
446
|
|
|
442
|
-
// Check margin from view edges to avoid detecting screen borders
|
|
443
|
-
// Use smaller margin (2%) to be less restrictive
|
|
444
|
-
val margin = minDim * 0.02
|
|
445
|
-
if (rectangle.topLeft.x < margin || rectangle.topLeft.y < margin ||
|
|
446
|
-
rectangle.topRight.x > srcMat.cols() - margin || rectangle.topRight.y < margin ||
|
|
447
|
-
rectangle.bottomLeft.x < margin || rectangle.bottomLeft.y > srcMat.rows() - margin ||
|
|
448
|
-
rectangle.bottomRight.x > srcMat.cols() - margin || rectangle.bottomRight.y > srcMat.rows() - margin) {
|
|
449
|
-
return false
|
|
450
|
-
}
|
|
451
|
-
|
|
452
447
|
return true
|
|
453
448
|
}
|
|
454
449
|
|