react-native-rectangle-doc-scanner 3.251.0 → 4.0.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.
|
@@ -580,7 +580,7 @@ class CameraController(
|
|
|
580
580
|
val uprightWidth = if (rotationDegrees == 90 || rotationDegrees == 270) imageHeight else imageWidth
|
|
581
581
|
val uprightHeight = if (rotationDegrees == 90 || rotationDegrees == 270) imageWidth else imageHeight
|
|
582
582
|
val openCvRect = if (mlBox != null) {
|
|
583
|
-
val expanded = expandRect(mlBox, uprightWidth, uprightHeight, 0.
|
|
583
|
+
val expanded = expandRect(mlBox, uprightWidth, uprightHeight, 0.1f)
|
|
584
584
|
DocumentDetector.detectRectangleInYUVWithRoi(
|
|
585
585
|
nv21,
|
|
586
586
|
imageWidth,
|
|
@@ -592,7 +592,7 @@ class CameraController(
|
|
|
592
592
|
DocumentDetector.detectRectangleInYUV(nv21, imageWidth, imageHeight, rotationDegrees)
|
|
593
593
|
}
|
|
594
594
|
if (openCvRect == null) {
|
|
595
|
-
mlBox?.let { boxToRectangle(it) }
|
|
595
|
+
mlBox?.let { boxToRectangle(insetBox(it, 0.85f)) }
|
|
596
596
|
} else {
|
|
597
597
|
openCvRect
|
|
598
598
|
}
|
|
@@ -621,6 +621,18 @@ class CameraController(
|
|
|
621
621
|
return Rect(left, top, right, bottom)
|
|
622
622
|
}
|
|
623
623
|
|
|
624
|
+
private fun insetBox(box: Rect, ratio: Float): Rect {
|
|
625
|
+
if (ratio >= 1f) return box
|
|
626
|
+
val insetX = ((1f - ratio) * box.width() / 2f).toInt()
|
|
627
|
+
val insetY = ((1f - ratio) * box.height() / 2f).toInt()
|
|
628
|
+
return Rect(
|
|
629
|
+
box.left + insetX,
|
|
630
|
+
box.top + insetY,
|
|
631
|
+
box.right - insetX,
|
|
632
|
+
box.bottom - insetY
|
|
633
|
+
)
|
|
634
|
+
}
|
|
635
|
+
|
|
624
636
|
private fun smoothRectangle(current: Rectangle?): Rectangle? {
|
|
625
637
|
val now = System.currentTimeMillis()
|
|
626
638
|
val last = lastRectangle
|
|
@@ -356,7 +356,7 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
356
356
|
}
|
|
357
357
|
|
|
358
358
|
// Process image with detected rectangle
|
|
359
|
-
val shouldCrop = detectedRectangle != null
|
|
359
|
+
val shouldCrop = detectedRectangle != null
|
|
360
360
|
val processed = ImageProcessor.processImage(
|
|
361
361
|
imagePath = imageFile.absolutePath,
|
|
362
362
|
rectangle = detectedRectangle,
|