react-native-rectangle-doc-scanner 3.250.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.
|
@@ -77,7 +77,6 @@ class CameraController(
|
|
|
77
77
|
|
|
78
78
|
companion object {
|
|
79
79
|
private const val TAG = "CameraController"
|
|
80
|
-
private const val ANALYSIS_MAX_AREA = 2560 * 1920
|
|
81
80
|
private const val ANALYSIS_ASPECT_TOLERANCE = 0.15
|
|
82
81
|
}
|
|
83
82
|
|
|
@@ -219,7 +218,7 @@ class CameraController(
|
|
|
219
218
|
previewSize = chooseBestSize(previewSizes, viewAspect, null, preferClosestAspect = true)
|
|
220
219
|
|
|
221
220
|
val analysisSizes = streamConfigMap.getOutputSizes(ImageFormat.YUV_420_888)
|
|
222
|
-
analysisSize = chooseBestSize(analysisSizes, viewAspect,
|
|
221
|
+
analysisSize = chooseBestSize(analysisSizes, viewAspect, null, preferClosestAspect = true)
|
|
223
222
|
|
|
224
223
|
val captureSizes = streamConfigMap.getOutputSizes(ImageFormat.JPEG)
|
|
225
224
|
captureSize = captureSizes?.maxByOrNull { it.width * it.height }
|
|
@@ -581,7 +580,7 @@ class CameraController(
|
|
|
581
580
|
val uprightWidth = if (rotationDegrees == 90 || rotationDegrees == 270) imageHeight else imageWidth
|
|
582
581
|
val uprightHeight = if (rotationDegrees == 90 || rotationDegrees == 270) imageWidth else imageHeight
|
|
583
582
|
val openCvRect = if (mlBox != null) {
|
|
584
|
-
val expanded = expandRect(mlBox, uprightWidth, uprightHeight, 0.
|
|
583
|
+
val expanded = expandRect(mlBox, uprightWidth, uprightHeight, 0.1f)
|
|
585
584
|
DocumentDetector.detectRectangleInYUVWithRoi(
|
|
586
585
|
nv21,
|
|
587
586
|
imageWidth,
|
|
@@ -593,7 +592,7 @@ class CameraController(
|
|
|
593
592
|
DocumentDetector.detectRectangleInYUV(nv21, imageWidth, imageHeight, rotationDegrees)
|
|
594
593
|
}
|
|
595
594
|
if (openCvRect == null) {
|
|
596
|
-
mlBox?.let { boxToRectangle(it) }
|
|
595
|
+
mlBox?.let { boxToRectangle(insetBox(it, 0.85f)) }
|
|
597
596
|
} else {
|
|
598
597
|
openCvRect
|
|
599
598
|
}
|
|
@@ -622,6 +621,18 @@ class CameraController(
|
|
|
622
621
|
return Rect(left, top, right, bottom)
|
|
623
622
|
}
|
|
624
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
|
+
|
|
625
636
|
private fun smoothRectangle(current: Rectangle?): Rectangle? {
|
|
626
637
|
val now = System.currentTimeMillis()
|
|
627
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,
|