react-native-rectangle-doc-scanner 4.7.0 → 4.9.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.
|
@@ -517,17 +517,27 @@ class CameraController(
|
|
|
517
517
|
val bufferWidth = if (rotation == 90 || rotation == 270) preview.height.toFloat() else preview.width.toFloat()
|
|
518
518
|
val bufferHeight = if (rotation == 90 || rotation == 270) preview.width.toFloat() else preview.height.toFloat()
|
|
519
519
|
|
|
520
|
-
val
|
|
521
|
-
val
|
|
522
|
-
val centerX = viewRect.centerX()
|
|
523
|
-
val centerY = viewRect.centerY()
|
|
520
|
+
val centerX = viewWidth / 2f
|
|
521
|
+
val centerY = viewHeight / 2f
|
|
524
522
|
|
|
525
523
|
val matrix = Matrix()
|
|
526
|
-
|
|
527
|
-
|
|
524
|
+
|
|
525
|
+
// Apply transformations in correct order:
|
|
526
|
+
// 1. Translate to center
|
|
527
|
+
matrix.postTranslate(-centerX, -centerY)
|
|
528
|
+
|
|
529
|
+
// 2. Rotate around origin
|
|
530
|
+
if (rotation != 0) {
|
|
531
|
+
matrix.postRotate(rotation.toFloat())
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// 3. Scale to fill view
|
|
528
535
|
val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
|
|
529
|
-
matrix.postScale(scale, scale
|
|
530
|
-
|
|
536
|
+
matrix.postScale(scale, scale)
|
|
537
|
+
|
|
538
|
+
// 4. Translate back to center
|
|
539
|
+
matrix.postTranslate(centerX, centerY)
|
|
540
|
+
|
|
531
541
|
previewView.setTransform(matrix)
|
|
532
542
|
}
|
|
533
543
|
|
|
@@ -171,10 +171,10 @@ class DocumentDetector {
|
|
|
171
171
|
}
|
|
172
172
|
|
|
173
173
|
// Apply a light blur to reduce noise without killing small edges.
|
|
174
|
-
Imgproc.GaussianBlur(grayMat, blurredMat, Size(
|
|
174
|
+
Imgproc.GaussianBlur(grayMat, blurredMat, Size(5.0, 5.0), 0.0)
|
|
175
175
|
|
|
176
|
-
// Apply Canny edge detection with lower thresholds for
|
|
177
|
-
Imgproc.Canny(blurredMat, cannyMat,
|
|
176
|
+
// Apply Canny edge detection with lower thresholds for better corner detection.
|
|
177
|
+
Imgproc.Canny(blurredMat, cannyMat, 30.0, 90.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()
|
|
@@ -188,12 +188,13 @@ class DocumentDetector {
|
|
|
188
188
|
Point(rectangle.bottomLeft.x.coerceIn(0.0, maxX), rectangle.bottomLeft.y.coerceIn(0.0, maxY)),
|
|
189
189
|
Point(rectangle.bottomRight.x.coerceIn(0.0, maxX), rectangle.bottomRight.y.coerceIn(0.0, maxY))
|
|
190
190
|
)
|
|
191
|
-
|
|
191
|
+
// Use larger window for better sub-pixel corner refinement (matching iOS high accuracy)
|
|
192
|
+
val criteria = TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER, 40, 0.001)
|
|
192
193
|
return try {
|
|
193
194
|
Imgproc.cornerSubPix(
|
|
194
195
|
gray,
|
|
195
196
|
points,
|
|
196
|
-
Size(
|
|
197
|
+
Size(11.0, 11.0), // Increased from 5x5 to 11x11 for better accuracy
|
|
197
198
|
Size(-1.0, -1.0),
|
|
198
199
|
criteria
|
|
199
200
|
)
|
|
@@ -227,11 +228,13 @@ class DocumentDetector {
|
|
|
227
228
|
val approx = MatOfPoint2f()
|
|
228
229
|
val contour2f = MatOfPoint2f(*contour.toArray())
|
|
229
230
|
val arcLength = Imgproc.arcLength(contour2f, true)
|
|
230
|
-
|
|
231
|
+
// Reduced epsilon for more accurate corner detection (matching iOS high accuracy)
|
|
232
|
+
val epsilon = 0.01 * arcLength
|
|
231
233
|
Imgproc.approxPolyDP(contour2f, approx, epsilon, true)
|
|
232
234
|
val relaxed = if (approx.total() != 4L) {
|
|
233
235
|
MatOfPoint2f().apply {
|
|
234
|
-
|
|
236
|
+
// Reduced fallback epsilon for better corner accuracy
|
|
237
|
+
Imgproc.approxPolyDP(contour2f, this, 0.02 * arcLength, true)
|
|
235
238
|
}
|
|
236
239
|
} else {
|
|
237
240
|
null
|