react-native-rectangle-doc-scanner 4.3.0 → 4.4.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.
@@ -179,6 +179,32 @@ class DocumentDetector {
179
179
  Imgproc.morphologyEx(cannyMat, morphMat, Imgproc.MORPH_CLOSE, kernel)
180
180
  kernel.release()
181
181
 
182
+ fun refineRectangle(gray: Mat, rectangle: Rectangle): Rectangle {
183
+ val maxX = (gray.cols() - 1).toDouble().coerceAtLeast(1.0)
184
+ val maxY = (gray.rows() - 1).toDouble().coerceAtLeast(1.0)
185
+ val points = MatOfPoint2f(
186
+ Point(rectangle.topLeft.x.coerceIn(0.0, maxX), rectangle.topLeft.y.coerceIn(0.0, maxY)),
187
+ Point(rectangle.topRight.x.coerceIn(0.0, maxX), rectangle.topRight.y.coerceIn(0.0, maxY)),
188
+ Point(rectangle.bottomLeft.x.coerceIn(0.0, maxX), rectangle.bottomLeft.y.coerceIn(0.0, maxY)),
189
+ Point(rectangle.bottomRight.x.coerceIn(0.0, maxX), rectangle.bottomRight.y.coerceIn(0.0, maxY))
190
+ )
191
+ val criteria = TermCriteria(TermCriteria.EPS + TermCriteria.MAX_ITER, 30, 0.01)
192
+ return try {
193
+ Imgproc.cornerSubPix(
194
+ gray,
195
+ points,
196
+ Size(5.0, 5.0),
197
+ Size(-1.0, -1.0),
198
+ criteria
199
+ )
200
+ orderPoints(points.toArray())
201
+ } catch (e: Exception) {
202
+ rectangle
203
+ } finally {
204
+ points.release()
205
+ }
206
+ }
207
+
182
208
  fun findLargestRectangle(source: Mat): Rectangle? {
183
209
  val contours = mutableListOf<MatOfPoint>()
184
210
  val hierarchy = Mat()
@@ -216,7 +242,7 @@ class DocumentDetector {
216
242
  val points = quad.toArray()
217
243
  if (contourArea > largestArea) {
218
244
  largestArea = contourArea
219
- largestRectangle = orderPoints(points)
245
+ largestRectangle = refineRectangle(grayMat, orderPoints(points))
220
246
  }
221
247
  } else {
222
248
  // Fallback: use rotated bounding box when contour is near-rectangular.
@@ -230,7 +256,7 @@ class DocumentDetector {
230
256
  val boxPoints = Array(4) { Point() }
231
257
  rotated.points(boxPoints)
232
258
  largestArea = contourArea
233
- largestRectangle = orderPoints(boxPoints)
259
+ largestRectangle = refineRectangle(grayMat, orderPoints(boxPoints))
234
260
  }
235
261
  }
236
262
  }
@@ -573,6 +573,7 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
573
573
  }, []);
574
574
  const activePreviewImage = croppedImageData ? getActivePreviewImage(croppedImageData) : null;
575
575
  return (react_1.default.createElement(react_native_1.View, { style: styles.container },
576
+ react_native_1.Platform.OS === 'android' && (react_1.default.createElement(react_native_1.StatusBar, { translucent: true, backgroundColor: "transparent" })),
576
577
  croppedImageData ? (
577
578
  // check_DP: Show confirmation screen
578
579
  react_1.default.createElement(react_native_1.View, { style: styles.confirmationContainer },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
4
4
  "description": "Native-backed document scanner for React Native with customizable overlays.",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",
@@ -7,6 +7,7 @@ import {
7
7
  NativeModules,
8
8
  Platform,
9
9
  StyleSheet,
10
+ StatusBar,
10
11
  Text,
11
12
  TouchableOpacity,
12
13
  View,
@@ -775,6 +776,9 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
775
776
 
776
777
  return (
777
778
  <View style={styles.container}>
779
+ {Platform.OS === 'android' && (
780
+ <StatusBar translucent backgroundColor="transparent" />
781
+ )}
778
782
  {croppedImageData ? (
779
783
  // check_DP: Show confirmation screen
780
784
  <View style={styles.confirmationContainer}>