react-native-rectangle-doc-scanner 10.36.0 → 10.37.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,23 +457,41 @@ class CameraController(
|
|
|
457
457
|
else -> 0
|
|
458
458
|
}
|
|
459
459
|
|
|
460
|
-
//
|
|
461
|
-
//
|
|
462
|
-
|
|
460
|
+
// For sensor 90° (phones): coordinates are in sensor space, need 90° rotation
|
|
461
|
+
// For sensor 0° (tablets): coordinates are already correct orientation
|
|
462
|
+
|
|
463
|
+
// First rotate coordinates if needed (sensor 90° means image is rotated 90° CW in sensor space)
|
|
464
|
+
fun rotatePoint(point: org.opencv.core.Point): org.opencv.core.Point {
|
|
465
|
+
return if (sensorOrientation == 90) {
|
|
466
|
+
// Rotate 90° CCW to convert from sensor space to display space
|
|
467
|
+
org.opencv.core.Point(
|
|
468
|
+
point.y,
|
|
469
|
+
imageWidth - point.x
|
|
470
|
+
)
|
|
471
|
+
} else {
|
|
472
|
+
point
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
// After rotation, determine final dimensions
|
|
477
|
+
val finalWidth = if (sensorOrientation == 90) imageHeight else imageWidth
|
|
478
|
+
val finalHeight = if (sensorOrientation == 90) imageWidth else imageHeight
|
|
463
479
|
|
|
464
|
-
|
|
465
|
-
val
|
|
466
|
-
val
|
|
480
|
+
// Then apply fit-center scaling
|
|
481
|
+
val scaleX = viewWidth / finalWidth.toFloat()
|
|
482
|
+
val scaleY = viewHeight / finalHeight.toFloat()
|
|
483
|
+
val scale = scaleX.coerceAtMost(scaleY)
|
|
467
484
|
|
|
468
|
-
val scaledWidth =
|
|
469
|
-
val scaledHeight =
|
|
485
|
+
val scaledWidth = finalWidth * scale
|
|
486
|
+
val scaledHeight = finalHeight * scale
|
|
470
487
|
val offsetX = (viewWidth - scaledWidth) / 2f
|
|
471
488
|
val offsetY = (viewHeight - scaledHeight) / 2f
|
|
472
489
|
|
|
473
490
|
fun transformPoint(point: org.opencv.core.Point): org.opencv.core.Point {
|
|
491
|
+
val rotated = rotatePoint(point)
|
|
474
492
|
return org.opencv.core.Point(
|
|
475
|
-
|
|
476
|
-
|
|
493
|
+
rotated.x * scale + offsetX,
|
|
494
|
+
rotated.y * scale + offsetY
|
|
477
495
|
)
|
|
478
496
|
}
|
|
479
497
|
|
|
@@ -484,11 +502,11 @@ class CameraController(
|
|
|
484
502
|
transformPoint(rectangle.bottomRight)
|
|
485
503
|
)
|
|
486
504
|
|
|
487
|
-
Log.d(TAG, "[MAPPING]
|
|
488
|
-
|
|
489
|
-
"Offset: ($offsetX, $offsetY)")
|
|
505
|
+
Log.d(TAG, "[MAPPING] Sensor: ${sensorOrientation}°, Image: ${imageWidth}x${imageHeight} → Final: ${finalWidth}x${finalHeight}")
|
|
506
|
+
Log.d(TAG, "[MAPPING] View: ${viewWidth.toInt()}x${viewHeight.toInt()}, Scale: $scale, Offset: ($offsetX, $offsetY)")
|
|
490
507
|
Log.d(TAG, "[MAPPING] TL: (${rectangle.topLeft.x}, ${rectangle.topLeft.y}) → " +
|
|
491
|
-
"(${
|
|
508
|
+
"Rotated: (${rotatePoint(rectangle.topLeft).x}, ${rotatePoint(rectangle.topLeft).y}) → " +
|
|
509
|
+
"Final: (${result.topLeft.x}, ${result.topLeft.y})")
|
|
492
510
|
|
|
493
511
|
return result
|
|
494
512
|
}
|
package/package.json
CHANGED