react-native-rectangle-doc-scanner 3.232.0 → 3.234.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.
|
@@ -7,6 +7,7 @@ import org.opencv.core.*
|
|
|
7
7
|
import org.opencv.imgproc.Imgproc
|
|
8
8
|
import kotlin.math.abs
|
|
9
9
|
import kotlin.math.max
|
|
10
|
+
import kotlin.math.min
|
|
10
11
|
import kotlin.math.sqrt
|
|
11
12
|
|
|
12
13
|
data class Rectangle(
|
|
@@ -228,6 +229,42 @@ class DocumentDetector {
|
|
|
228
229
|
return RectangleQuality.GOOD
|
|
229
230
|
}
|
|
230
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Evaluate rectangle quality in view coordinates (closer to iOS behavior).
|
|
234
|
+
*/
|
|
235
|
+
fun evaluateRectangleQualityInView(
|
|
236
|
+
rectangle: Rectangle,
|
|
237
|
+
viewWidth: Int,
|
|
238
|
+
viewHeight: Int
|
|
239
|
+
): RectangleQuality {
|
|
240
|
+
if (viewWidth == 0 || viewHeight == 0) {
|
|
241
|
+
return RectangleQuality.TOO_FAR
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
val minDim = min(viewWidth.toDouble(), viewHeight.toDouble())
|
|
245
|
+
val angleThreshold = max(60.0, minDim * 0.05)
|
|
246
|
+
|
|
247
|
+
val topYDiff = abs(rectangle.topRight.y - rectangle.topLeft.y)
|
|
248
|
+
val bottomYDiff = abs(rectangle.bottomLeft.y - rectangle.bottomRight.y)
|
|
249
|
+
val leftXDiff = abs(rectangle.topLeft.x - rectangle.bottomLeft.x)
|
|
250
|
+
val rightXDiff = abs(rectangle.topRight.x - rectangle.bottomRight.x)
|
|
251
|
+
|
|
252
|
+
if (topYDiff > angleThreshold || bottomYDiff > angleThreshold || leftXDiff > angleThreshold || rightXDiff > angleThreshold) {
|
|
253
|
+
return RectangleQuality.BAD_ANGLE
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
val margin = max(150.0, minDim * 0.15)
|
|
257
|
+
if (rectangle.topLeft.y > margin ||
|
|
258
|
+
rectangle.topRight.y > margin ||
|
|
259
|
+
rectangle.bottomLeft.y < (viewHeight - margin) ||
|
|
260
|
+
rectangle.bottomRight.y < (viewHeight - margin)
|
|
261
|
+
) {
|
|
262
|
+
return RectangleQuality.TOO_FAR
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return RectangleQuality.GOOD
|
|
266
|
+
}
|
|
267
|
+
|
|
231
268
|
/**
|
|
232
269
|
* Calculate perimeter of rectangle
|
|
233
270
|
*/
|
|
@@ -186,17 +186,17 @@ class DocumentScannerView(context: ThemedReactContext) : FrameLayout(context), L
|
|
|
186
186
|
}
|
|
187
187
|
lastDetectionTimestamp = now
|
|
188
188
|
|
|
189
|
-
val quality = if (rectangle != null) {
|
|
190
|
-
DocumentDetector.evaluateRectangleQuality(rectangle, imageWidth, imageHeight)
|
|
191
|
-
} else {
|
|
192
|
-
RectangleQuality.TOO_FAR
|
|
193
|
-
}
|
|
194
|
-
|
|
195
189
|
val rectangleOnScreen = if (rectangle != null && width > 0 && height > 0) {
|
|
196
190
|
DocumentDetector.transformRectangleToViewCoordinates(rectangle, imageWidth, imageHeight, width, height)
|
|
197
191
|
} else {
|
|
198
192
|
null
|
|
199
193
|
}
|
|
194
|
+
val quality = when {
|
|
195
|
+
rectangleOnScreen != null && width > 0 && height > 0 ->
|
|
196
|
+
DocumentDetector.evaluateRectangleQualityInView(rectangleOnScreen, width, height)
|
|
197
|
+
rectangle != null -> DocumentDetector.evaluateRectangleQuality(rectangle, imageWidth, imageHeight)
|
|
198
|
+
else -> RectangleQuality.TOO_FAR
|
|
199
|
+
}
|
|
200
200
|
|
|
201
201
|
post {
|
|
202
202
|
onRectangleDetected(rectangleOnScreen, rectangle, quality, imageWidth, imageHeight)
|
package/package.json
CHANGED