react-native-rectangle-doc-scanner 4.2.0 → 4.3.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.
|
@@ -588,7 +588,7 @@ class CameraController(
|
|
|
588
588
|
val uprightWidth = if (rotationDegrees == 90 || rotationDegrees == 270) imageHeight else imageWidth
|
|
589
589
|
val uprightHeight = if (rotationDegrees == 90 || rotationDegrees == 270) imageWidth else imageHeight
|
|
590
590
|
val openCvRect = if (mlBox != null) {
|
|
591
|
-
val expanded = expandRect(mlBox, uprightWidth, uprightHeight, 0.
|
|
591
|
+
val expanded = expandRect(mlBox, uprightWidth, uprightHeight, 0.25f)
|
|
592
592
|
DocumentDetector.detectRectangleInYUVWithRoi(
|
|
593
593
|
nv21,
|
|
594
594
|
imageWidth,
|
|
@@ -600,7 +600,7 @@ class CameraController(
|
|
|
600
600
|
DocumentDetector.detectRectangleInYUV(nv21, imageWidth, imageHeight, rotationDegrees)
|
|
601
601
|
}
|
|
602
602
|
if (openCvRect == null) {
|
|
603
|
-
mlBox?.let { boxToRectangle(insetBox(it, 0.
|
|
603
|
+
mlBox?.let { boxToRectangle(insetBox(it, 0.9f)) }
|
|
604
604
|
} else {
|
|
605
605
|
openCvRect
|
|
606
606
|
}
|
|
@@ -173,8 +173,8 @@ class DocumentDetector {
|
|
|
173
173
|
// Apply a light blur to reduce noise without killing small edges.
|
|
174
174
|
Imgproc.GaussianBlur(grayMat, blurredMat, Size(3.0, 3.0), 0.0)
|
|
175
175
|
|
|
176
|
-
// Apply Canny edge detection with
|
|
177
|
-
Imgproc.Canny(blurredMat, cannyMat,
|
|
176
|
+
// Apply Canny edge detection with lower thresholds for small, low-contrast documents.
|
|
177
|
+
Imgproc.Canny(blurredMat, cannyMat, 40.0, 120.0)
|
|
178
178
|
val kernel = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, Size(3.0, 3.0))
|
|
179
179
|
Imgproc.morphologyEx(cannyMat, morphMat, Imgproc.MORPH_CLOSE, kernel)
|
|
180
180
|
kernel.release()
|
|
@@ -218,6 +218,21 @@ class DocumentDetector {
|
|
|
218
218
|
largestArea = contourArea
|
|
219
219
|
largestRectangle = orderPoints(points)
|
|
220
220
|
}
|
|
221
|
+
} else {
|
|
222
|
+
// Fallback: use rotated bounding box when contour is near-rectangular.
|
|
223
|
+
val contour2fForRect = MatOfPoint2f(*contour.toArray())
|
|
224
|
+
val rotated = Imgproc.minAreaRect(contour2fForRect)
|
|
225
|
+
contour2fForRect.release()
|
|
226
|
+
val rectArea = rotated.size.area()
|
|
227
|
+
if (rectArea > 1.0) {
|
|
228
|
+
val rectangularity = contourArea / rectArea
|
|
229
|
+
if (rectangularity >= 0.6 && contourArea > largestArea) {
|
|
230
|
+
val boxPoints = Array(4) { Point() }
|
|
231
|
+
rotated.points(boxPoints)
|
|
232
|
+
largestArea = contourArea
|
|
233
|
+
largestRectangle = orderPoints(boxPoints)
|
|
234
|
+
}
|
|
235
|
+
}
|
|
221
236
|
}
|
|
222
237
|
|
|
223
238
|
approx.release()
|