react-native-rectangle-doc-scanner 3.235.0 → 3.237.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.
|
@@ -7,6 +7,7 @@ import android.graphics.Bitmap
|
|
|
7
7
|
import android.graphics.BitmapFactory
|
|
8
8
|
import android.graphics.Matrix
|
|
9
9
|
import android.graphics.SurfaceTexture
|
|
10
|
+
import android.graphics.RectF
|
|
10
11
|
import android.graphics.ImageFormat
|
|
11
12
|
import android.hardware.camera2.CameraCaptureSession
|
|
12
13
|
import android.hardware.camera2.CameraCharacteristics
|
|
@@ -445,12 +446,17 @@ class CameraController(
|
|
|
445
446
|
val bufferWidth = if (rotation == 90 || rotation == 270) preview.height.toFloat() else preview.width.toFloat()
|
|
446
447
|
val bufferHeight = if (rotation == 90 || rotation == 270) preview.width.toFloat() else preview.height.toFloat()
|
|
447
448
|
|
|
448
|
-
val
|
|
449
|
+
val viewRect = RectF(0f, 0f, viewWidth, viewHeight)
|
|
450
|
+
val bufferRect = RectF(0f, 0f, bufferWidth, bufferHeight)
|
|
451
|
+
val centerX = viewRect.centerX()
|
|
452
|
+
val centerY = viewRect.centerY()
|
|
453
|
+
|
|
449
454
|
val matrix = Matrix()
|
|
450
|
-
|
|
451
|
-
|
|
455
|
+
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
456
|
+
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
|
|
452
457
|
|
|
453
|
-
|
|
458
|
+
val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
|
|
459
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
454
460
|
matrix.postRotate(rotation.toFloat(), centerX, centerY)
|
|
455
461
|
previewView.setTransform(matrix)
|
|
456
462
|
}
|
|
@@ -138,7 +138,7 @@ class DocumentDetector {
|
|
|
138
138
|
// Find the largest contour that approximates to a quadrilateral
|
|
139
139
|
var largestRectangle: Rectangle? = null
|
|
140
140
|
var largestArea = 0.0
|
|
141
|
-
val minArea = max(
|
|
141
|
+
val minArea = max(600.0, (srcMat.rows() * srcMat.cols()) * 0.001)
|
|
142
142
|
|
|
143
143
|
for (contour in contours) {
|
|
144
144
|
val contourArea = Imgproc.contourArea(contour)
|
|
@@ -242,7 +242,7 @@ class DocumentDetector {
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
val minDim = kotlin.math.min(viewWidth.toDouble(), viewHeight.toDouble())
|
|
245
|
-
val angleThreshold = max(
|
|
245
|
+
val angleThreshold = max(40.0, minDim * 0.06)
|
|
246
246
|
|
|
247
247
|
val topYDiff = abs(rectangle.topRight.y - rectangle.topLeft.y)
|
|
248
248
|
val bottomYDiff = abs(rectangle.bottomLeft.y - rectangle.bottomRight.y)
|
|
@@ -253,7 +253,7 @@ class DocumentDetector {
|
|
|
253
253
|
return RectangleQuality.BAD_ANGLE
|
|
254
254
|
}
|
|
255
255
|
|
|
256
|
-
val margin = max(
|
|
256
|
+
val margin = max(80.0, minDim * 0.08)
|
|
257
257
|
if (rectangle.topLeft.y > margin ||
|
|
258
258
|
rectangle.topRight.y > margin ||
|
|
259
259
|
rectangle.bottomLeft.y < (viewHeight - margin) ||
|
package/package.json
CHANGED