react-native-rectangle-doc-scanner 10.34.0 → 10.36.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.
|
@@ -457,70 +457,23 @@ class CameraController(
|
|
|
457
457
|
else -> 0
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
-
//
|
|
461
|
-
//
|
|
462
|
-
//
|
|
460
|
+
// Simple fit-center scaling like Camera2 did
|
|
461
|
+
// The image analysis coordinates are in the image's coordinate space (imageWidth x imageHeight)
|
|
462
|
+
// We just need to scale and center them to the view, matching how Camera2 worked.
|
|
463
463
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
val tabletUpsideDownFix = if (sensorOrientation == 0 && displayRotationDegrees == 90) 180 else 0
|
|
467
|
-
val textureViewRotation = ((displayRotationDegrees + tabletUpsideDownFix) % 360).toFloat()
|
|
468
|
-
|
|
469
|
-
// But the image analysis coordinates are in sensor orientation. So we need to apply
|
|
470
|
-
// the SAME rotation that the TextureView applies to align coordinates with display.
|
|
471
|
-
val rotationDegrees = textureViewRotation
|
|
472
|
-
|
|
473
|
-
Log.d(TAG, "[MAPPING] Image: ${imageWidth}x${imageHeight}, Sensor: ${sensorOrientation}°, " +
|
|
474
|
-
"Display: ${displayRotationDegrees}°, TextureView rotation: ${textureViewRotation}°, " +
|
|
475
|
-
"Coordinate rotation: ${rotationDegrees}°")
|
|
476
|
-
|
|
477
|
-
// Apply rotation to coordinates to match display orientation
|
|
478
|
-
fun rotatePoint(point: org.opencv.core.Point): org.opencv.core.Point {
|
|
479
|
-
return when (rotationDegrees.toInt()) {
|
|
480
|
-
90 -> org.opencv.core.Point(
|
|
481
|
-
imageHeight - point.y,
|
|
482
|
-
point.x
|
|
483
|
-
)
|
|
484
|
-
180 -> org.opencv.core.Point(
|
|
485
|
-
imageWidth - point.x,
|
|
486
|
-
imageHeight - point.y
|
|
487
|
-
)
|
|
488
|
-
270 -> org.opencv.core.Point(
|
|
489
|
-
point.y,
|
|
490
|
-
imageWidth - point.x
|
|
491
|
-
)
|
|
492
|
-
else -> point // 0 degrees, no rotation
|
|
493
|
-
}
|
|
494
|
-
}
|
|
495
|
-
|
|
496
|
-
// Determine dimensions after rotation
|
|
497
|
-
val rotatedImageWidth = if (rotationDegrees == 90f || rotationDegrees == 270f) {
|
|
498
|
-
imageHeight
|
|
499
|
-
} else {
|
|
500
|
-
imageWidth
|
|
501
|
-
}
|
|
502
|
-
val rotatedImageHeight = if (rotationDegrees == 90f || rotationDegrees == 270f) {
|
|
503
|
-
imageWidth
|
|
504
|
-
} else {
|
|
505
|
-
imageHeight
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// Calculate scaling to fit the rotated image into the view (matching transform)
|
|
509
|
-
val scaleX = viewWidth / rotatedImageWidth.toFloat()
|
|
510
|
-
val scaleY = viewHeight / rotatedImageHeight.toFloat()
|
|
464
|
+
val scaleX = viewWidth / imageWidth.toFloat()
|
|
465
|
+
val scaleY = viewHeight / imageHeight.toFloat()
|
|
511
466
|
val scale = scaleX.coerceAtMost(scaleY) // Fit (preserve aspect ratio)
|
|
512
467
|
|
|
513
|
-
val scaledWidth =
|
|
514
|
-
val scaledHeight =
|
|
468
|
+
val scaledWidth = imageWidth * scale
|
|
469
|
+
val scaledHeight = imageHeight * scale
|
|
515
470
|
val offsetX = (viewWidth - scaledWidth) / 2f
|
|
516
471
|
val offsetY = (viewHeight - scaledHeight) / 2f
|
|
517
472
|
|
|
518
|
-
// Transform coordinates: rotate first, then scale and center
|
|
519
473
|
fun transformPoint(point: org.opencv.core.Point): org.opencv.core.Point {
|
|
520
|
-
val rotated = rotatePoint(point)
|
|
521
474
|
return org.opencv.core.Point(
|
|
522
|
-
|
|
523
|
-
|
|
475
|
+
point.x * scale + offsetX,
|
|
476
|
+
point.y * scale + offsetY
|
|
524
477
|
)
|
|
525
478
|
}
|
|
526
479
|
|
|
@@ -531,8 +484,11 @@ class CameraController(
|
|
|
531
484
|
transformPoint(rectangle.bottomRight)
|
|
532
485
|
)
|
|
533
486
|
|
|
534
|
-
Log.d(TAG, "[MAPPING]
|
|
535
|
-
"
|
|
487
|
+
Log.d(TAG, "[MAPPING] Simple fit-center: Image ${imageWidth}x${imageHeight}, " +
|
|
488
|
+
"View ${viewWidth.toInt()}x${viewHeight.toInt()}, Scale: $scale, " +
|
|
489
|
+
"Offset: ($offsetX, $offsetY)")
|
|
490
|
+
Log.d(TAG, "[MAPPING] TL: (${rectangle.topLeft.x}, ${rectangle.topLeft.y}) → " +
|
|
491
|
+
"(${result.topLeft.x}, ${result.topLeft.y})")
|
|
536
492
|
|
|
537
493
|
return result
|
|
538
494
|
}
|
package/package.json
CHANGED