react-native-rectangle-doc-scanner 0.38.0 → 0.39.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.
- package/dist/DocScanner.js +17 -2
- package/package.json +1 -1
- package/src/DocScanner.tsx +17 -2
package/dist/DocScanner.js
CHANGED
|
@@ -222,9 +222,24 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
222
222
|
if (areaRatio < 0.005 || areaRatio > 0.95) {
|
|
223
223
|
continue;
|
|
224
224
|
}
|
|
225
|
+
// Try to use convex hull for better corner detection
|
|
226
|
+
let contourToUse = contour;
|
|
227
|
+
try {
|
|
228
|
+
step = `contour_${i}_convexHull`;
|
|
229
|
+
reportStage(step);
|
|
230
|
+
const hull = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.PointVector);
|
|
231
|
+
react_native_fast_opencv_1.OpenCV.invoke('convexHull', contour, hull, false, true);
|
|
232
|
+
contourToUse = hull;
|
|
233
|
+
}
|
|
234
|
+
catch (err) {
|
|
235
|
+
// If convexHull fails, use original contour
|
|
236
|
+
if (__DEV__) {
|
|
237
|
+
console.warn('[DocScanner] convexHull failed, using original contour');
|
|
238
|
+
}
|
|
239
|
+
}
|
|
225
240
|
step = `contour_${i}_arcLength`;
|
|
226
241
|
reportStage(step);
|
|
227
|
-
const { value: perimeter } = react_native_fast_opencv_1.OpenCV.invoke('arcLength',
|
|
242
|
+
const { value: perimeter } = react_native_fast_opencv_1.OpenCV.invoke('arcLength', contourToUse, true);
|
|
228
243
|
const approx = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.PointVector);
|
|
229
244
|
let approxArray = [];
|
|
230
245
|
// Try more epsilon values from 0.1% to 10% for difficult shapes
|
|
@@ -236,7 +251,7 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
236
251
|
const epsilon = epsilonValues[attempt] * perimeter;
|
|
237
252
|
step = `contour_${i}_approxPolyDP_attempt_${attempt}`;
|
|
238
253
|
reportStage(step);
|
|
239
|
-
react_native_fast_opencv_1.OpenCV.invoke('approxPolyDP',
|
|
254
|
+
react_native_fast_opencv_1.OpenCV.invoke('approxPolyDP', contourToUse, approx, epsilon, true);
|
|
240
255
|
step = `contour_${i}_toJS_attempt_${attempt}`;
|
|
241
256
|
reportStage(step);
|
|
242
257
|
const approxValue = react_native_fast_opencv_1.OpenCV.toJSValue(approx);
|
package/package.json
CHANGED
package/src/DocScanner.tsx
CHANGED
|
@@ -254,9 +254,24 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
254
254
|
continue;
|
|
255
255
|
}
|
|
256
256
|
|
|
257
|
+
// Try to use convex hull for better corner detection
|
|
258
|
+
let contourToUse = contour;
|
|
259
|
+
try {
|
|
260
|
+
step = `contour_${i}_convexHull`;
|
|
261
|
+
reportStage(step);
|
|
262
|
+
const hull = OpenCV.createObject(ObjectType.PointVector);
|
|
263
|
+
OpenCV.invoke('convexHull', contour, hull, false, true);
|
|
264
|
+
contourToUse = hull;
|
|
265
|
+
} catch (err) {
|
|
266
|
+
// If convexHull fails, use original contour
|
|
267
|
+
if (__DEV__) {
|
|
268
|
+
console.warn('[DocScanner] convexHull failed, using original contour');
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
257
272
|
step = `contour_${i}_arcLength`;
|
|
258
273
|
reportStage(step);
|
|
259
|
-
const { value: perimeter } = OpenCV.invoke('arcLength',
|
|
274
|
+
const { value: perimeter } = OpenCV.invoke('arcLength', contourToUse, true);
|
|
260
275
|
const approx = OpenCV.createObject(ObjectType.PointVector);
|
|
261
276
|
|
|
262
277
|
let approxArray: Array<{ x: number; y: number }> = [];
|
|
@@ -271,7 +286,7 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
271
286
|
const epsilon = epsilonValues[attempt] * perimeter;
|
|
272
287
|
step = `contour_${i}_approxPolyDP_attempt_${attempt}`;
|
|
273
288
|
reportStage(step);
|
|
274
|
-
OpenCV.invoke('approxPolyDP',
|
|
289
|
+
OpenCV.invoke('approxPolyDP', contourToUse, approx, epsilon, true);
|
|
275
290
|
|
|
276
291
|
step = `contour_${i}_toJS_attempt_${attempt}`;
|
|
277
292
|
reportStage(step);
|