react-native-rectangle-doc-scanner 10.35.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,74 +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
|
-
val
|
|
466
|
-
val textureViewRotation = ((displayRotationDegrees + tabletUpsideDownFix) % 360).toFloat()
|
|
467
|
-
|
|
468
|
-
// For coordinate mapping: we need to account for BOTH sensor orientation AND display rotation
|
|
469
|
-
// - Sensor 90° + Display 0°: Coordinates are in landscape sensor space, need 90° rotation to portrait
|
|
470
|
-
// - Sensor 0° + Display 90°: Coordinates are in portrait, need 270° rotation (display + fix)
|
|
471
|
-
val rotationDegrees = if (sensorOrientation == 90 && displayRotationDegrees == 0) {
|
|
472
|
-
90f // Rotate coordinates 90° to match portrait display
|
|
473
|
-
} else {
|
|
474
|
-
textureViewRotation // Use TextureView rotation
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
Log.d(TAG, "[MAPPING] Image: ${imageWidth}x${imageHeight}, Sensor: ${sensorOrientation}°, " +
|
|
478
|
-
"Display: ${displayRotationDegrees}°, TextureView rotation: ${textureViewRotation}°, " +
|
|
479
|
-
"Coordinate rotation: ${rotationDegrees}°")
|
|
480
|
-
|
|
481
|
-
// Apply rotation to coordinates to match display orientation
|
|
482
|
-
fun rotatePoint(point: org.opencv.core.Point): org.opencv.core.Point {
|
|
483
|
-
return when (rotationDegrees.toInt()) {
|
|
484
|
-
90 -> org.opencv.core.Point(
|
|
485
|
-
imageHeight - point.y,
|
|
486
|
-
point.x
|
|
487
|
-
)
|
|
488
|
-
180 -> org.opencv.core.Point(
|
|
489
|
-
imageWidth - point.x,
|
|
490
|
-
imageHeight - point.y
|
|
491
|
-
)
|
|
492
|
-
270 -> org.opencv.core.Point(
|
|
493
|
-
point.y,
|
|
494
|
-
imageWidth - point.x
|
|
495
|
-
)
|
|
496
|
-
else -> point // 0 degrees, no rotation
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
|
|
500
|
-
// Determine dimensions after rotation
|
|
501
|
-
val rotatedImageWidth = if (rotationDegrees == 90f || rotationDegrees == 270f) {
|
|
502
|
-
imageHeight
|
|
503
|
-
} else {
|
|
504
|
-
imageWidth
|
|
505
|
-
}
|
|
506
|
-
val rotatedImageHeight = if (rotationDegrees == 90f || rotationDegrees == 270f) {
|
|
507
|
-
imageWidth
|
|
508
|
-
} else {
|
|
509
|
-
imageHeight
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
// Calculate scaling to fit the rotated image into the view (matching transform)
|
|
513
|
-
val scaleX = viewWidth / rotatedImageWidth.toFloat()
|
|
514
|
-
val scaleY = viewHeight / rotatedImageHeight.toFloat()
|
|
464
|
+
val scaleX = viewWidth / imageWidth.toFloat()
|
|
465
|
+
val scaleY = viewHeight / imageHeight.toFloat()
|
|
515
466
|
val scale = scaleX.coerceAtMost(scaleY) // Fit (preserve aspect ratio)
|
|
516
467
|
|
|
517
|
-
val scaledWidth =
|
|
518
|
-
val scaledHeight =
|
|
468
|
+
val scaledWidth = imageWidth * scale
|
|
469
|
+
val scaledHeight = imageHeight * scale
|
|
519
470
|
val offsetX = (viewWidth - scaledWidth) / 2f
|
|
520
471
|
val offsetY = (viewHeight - scaledHeight) / 2f
|
|
521
472
|
|
|
522
|
-
// Transform coordinates: rotate first, then scale and center
|
|
523
473
|
fun transformPoint(point: org.opencv.core.Point): org.opencv.core.Point {
|
|
524
|
-
val rotated = rotatePoint(point)
|
|
525
474
|
return org.opencv.core.Point(
|
|
526
|
-
|
|
527
|
-
|
|
475
|
+
point.x * scale + offsetX,
|
|
476
|
+
point.y * scale + offsetY
|
|
528
477
|
)
|
|
529
478
|
}
|
|
530
479
|
|
|
@@ -535,8 +484,11 @@ class CameraController(
|
|
|
535
484
|
transformPoint(rectangle.bottomRight)
|
|
536
485
|
)
|
|
537
486
|
|
|
538
|
-
Log.d(TAG, "[MAPPING]
|
|
539
|
-
"
|
|
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})")
|
|
540
492
|
|
|
541
493
|
return result
|
|
542
494
|
}
|
package/package.json
CHANGED