react-native-rectangle-doc-scanner 3.139.0 → 3.140.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.
|
@@ -6,6 +6,7 @@ import org.opencv.android.Utils
|
|
|
6
6
|
import org.opencv.core.*
|
|
7
7
|
import org.opencv.imgproc.Imgproc
|
|
8
8
|
import kotlin.math.abs
|
|
9
|
+
import kotlin.math.max
|
|
9
10
|
import kotlin.math.sqrt
|
|
10
11
|
|
|
11
12
|
data class Rectangle(
|
|
@@ -249,14 +250,34 @@ class DocumentDetector {
|
|
|
249
250
|
viewWidth: Int,
|
|
250
251
|
viewHeight: Int
|
|
251
252
|
): Rectangle {
|
|
252
|
-
|
|
253
|
-
|
|
253
|
+
if (imageWidth == 0 || imageHeight == 0 || viewWidth == 0 || viewHeight == 0) {
|
|
254
|
+
return rectangle
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
val scale = max(
|
|
258
|
+
viewWidth.toDouble() / imageWidth.toDouble(),
|
|
259
|
+
viewHeight.toDouble() / imageHeight.toDouble()
|
|
260
|
+
)
|
|
261
|
+
|
|
262
|
+
val scaledImageWidth = imageWidth * scale
|
|
263
|
+
val scaledImageHeight = imageHeight * scale
|
|
264
|
+
val offsetX = (scaledImageWidth - viewWidth) / 2.0
|
|
265
|
+
val offsetY = (scaledImageHeight - viewHeight) / 2.0
|
|
266
|
+
|
|
267
|
+
fun mapPoint(point: Point): Point {
|
|
268
|
+
val x = (point.x * scale) - offsetX
|
|
269
|
+
val y = (point.y * scale) - offsetY
|
|
270
|
+
return Point(
|
|
271
|
+
x.coerceIn(0.0, viewWidth.toDouble()),
|
|
272
|
+
y.coerceIn(0.0, viewHeight.toDouble())
|
|
273
|
+
)
|
|
274
|
+
}
|
|
254
275
|
|
|
255
276
|
return Rectangle(
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
277
|
+
mapPoint(rectangle.topLeft),
|
|
278
|
+
mapPoint(rectangle.topRight),
|
|
279
|
+
mapPoint(rectangle.bottomLeft),
|
|
280
|
+
mapPoint(rectangle.bottomRight)
|
|
260
281
|
)
|
|
261
282
|
}
|
|
262
283
|
}
|
package/package.json
CHANGED