react-native-rectangle-doc-scanner 3.242.0 → 3.244.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.
- package/android/src/main/kotlin/com/reactnativerectangledocscanner/CameraController.kt +12 -4
- package/android/src/main/kotlin/com/reactnativerectangledocscanner/DocumentScannerView.kt +7 -1
- package/android/src/main/kotlin/com/reactnativerectangledocscanner/ImageProcessor.kt +2 -1
- package/package.json +1 -1
|
@@ -368,6 +368,8 @@ class CameraController(
|
|
|
368
368
|
|
|
369
369
|
private fun analyzeImage(image: Image) {
|
|
370
370
|
val rotationDegrees = computeRotationDegrees()
|
|
371
|
+
val imageWidth = image.width
|
|
372
|
+
val imageHeight = image.height
|
|
371
373
|
val inputImage = try {
|
|
372
374
|
InputImage.fromMediaImage(image, rotationDegrees)
|
|
373
375
|
} catch (e: Exception) {
|
|
@@ -390,15 +392,19 @@ class CameraController(
|
|
|
390
392
|
else -> boxToRectangle(mlBox)
|
|
391
393
|
}
|
|
392
394
|
|
|
393
|
-
val frameWidth = if (rotationDegrees == 90 || rotationDegrees == 270)
|
|
394
|
-
val frameHeight = if (rotationDegrees == 90 || rotationDegrees == 270)
|
|
395
|
+
val frameWidth = if (rotationDegrees == 90 || rotationDegrees == 270) imageHeight else imageWidth
|
|
396
|
+
val frameHeight = if (rotationDegrees == 90 || rotationDegrees == 270) imageWidth else imageHeight
|
|
395
397
|
onFrameAnalyzed?.invoke(smoothRectangle(rectangle), frameWidth, frameHeight)
|
|
396
398
|
}
|
|
397
399
|
.addOnFailureListener { e ->
|
|
398
400
|
Log.e(TAG, "[CAMERA2] ML Kit detection failed", e)
|
|
399
401
|
}
|
|
400
402
|
.addOnCompleteListener {
|
|
401
|
-
|
|
403
|
+
try {
|
|
404
|
+
image.close()
|
|
405
|
+
} catch (e: Exception) {
|
|
406
|
+
Log.w(TAG, "[CAMERA2] Failed to close image", e)
|
|
407
|
+
}
|
|
402
408
|
analysisInFlight.set(false)
|
|
403
409
|
}
|
|
404
410
|
}
|
|
@@ -487,7 +493,9 @@ class CameraController(
|
|
|
487
493
|
|
|
488
494
|
val matrix = Matrix()
|
|
489
495
|
bufferRect.offset(centerX - bufferRect.centerX(), centerY - bufferRect.centerY())
|
|
490
|
-
matrix.setRectToRect(
|
|
496
|
+
matrix.setRectToRect(viewRect, bufferRect, Matrix.ScaleToFit.FILL)
|
|
497
|
+
val scale = max(viewWidth / bufferWidth, viewHeight / bufferHeight)
|
|
498
|
+
matrix.postScale(scale, scale, centerX, centerY)
|
|
491
499
|
matrix.postRotate(rotation.toFloat(), centerX, centerY)
|
|
492
500
|
previewView.setTransform(matrix)
|
|
493
501
|
}
|
|
@@ -312,7 +312,13 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
312
312
|
try {
|
|
313
313
|
// Detect rectangle in captured image
|
|
314
314
|
val bitmap = BitmapFactory.decodeFile(imageFile.absolutePath)
|
|
315
|
-
|
|
315
|
+
?: throw IllegalStateException("decode_failed")
|
|
316
|
+
val detectedRectangle = try {
|
|
317
|
+
DocumentDetector.detectRectangle(bitmap)
|
|
318
|
+
} catch (e: Exception) {
|
|
319
|
+
Log.w(TAG, "Rectangle detection failed, using original image", e)
|
|
320
|
+
null
|
|
321
|
+
}
|
|
316
322
|
|
|
317
323
|
// Process image with detected rectangle
|
|
318
324
|
val shouldCrop = detectedRectangle != null && stableCounter > 0
|
|
@@ -194,7 +194,8 @@ object ImageProcessor {
|
|
|
194
194
|
saturation: Float = 1f,
|
|
195
195
|
shouldCrop: Boolean = true
|
|
196
196
|
): ProcessedImage {
|
|
197
|
-
|
|
197
|
+
val initialBitmap = BitmapFactory.decodeFile(imagePath)
|
|
198
|
+
?: throw IllegalStateException("decode_failed")
|
|
198
199
|
var croppedBitmap = initialBitmap
|
|
199
200
|
|
|
200
201
|
// Apply perspective correction if rectangle detected and cropping enabled
|
package/package.json
CHANGED