react-native-rectangle-doc-scanner 0.37.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 +23 -5
- package/package.json +1 -1
- package/src/DocScanner.tsx +23 -5
package/dist/DocScanner.js
CHANGED
|
@@ -219,21 +219,39 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
219
219
|
console.log('[DocScanner] area', area, 'ratio', areaRatio);
|
|
220
220
|
}
|
|
221
221
|
// Skip if area ratio is too small or too large
|
|
222
|
-
if (areaRatio < 0.
|
|
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
|
-
// Try epsilon values from 0.
|
|
231
|
-
const epsilonValues = [
|
|
245
|
+
// Try more epsilon values from 0.1% to 10% for difficult shapes
|
|
246
|
+
const epsilonValues = [
|
|
247
|
+
0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009,
|
|
248
|
+
0.01, 0.012, 0.015, 0.018, 0.02, 0.025, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1
|
|
249
|
+
];
|
|
232
250
|
for (let attempt = 0; attempt < epsilonValues.length; attempt += 1) {
|
|
233
251
|
const epsilon = epsilonValues[attempt] * perimeter;
|
|
234
252
|
step = `contour_${i}_approxPolyDP_attempt_${attempt}`;
|
|
235
253
|
reportStage(step);
|
|
236
|
-
react_native_fast_opencv_1.OpenCV.invoke('approxPolyDP',
|
|
254
|
+
react_native_fast_opencv_1.OpenCV.invoke('approxPolyDP', contourToUse, approx, epsilon, true);
|
|
237
255
|
step = `contour_${i}_toJS_attempt_${attempt}`;
|
|
238
256
|
reportStage(step);
|
|
239
257
|
const approxValue = react_native_fast_opencv_1.OpenCV.toJSValue(approx);
|
package/package.json
CHANGED
package/src/DocScanner.tsx
CHANGED
|
@@ -250,25 +250,43 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
250
250
|
}
|
|
251
251
|
|
|
252
252
|
// Skip if area ratio is too small or too large
|
|
253
|
-
if (areaRatio < 0.
|
|
253
|
+
if (areaRatio < 0.005 || areaRatio > 0.95) {
|
|
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 }> = [];
|
|
263
278
|
|
|
264
|
-
// Try epsilon values from 0.
|
|
265
|
-
const epsilonValues = [
|
|
279
|
+
// Try more epsilon values from 0.1% to 10% for difficult shapes
|
|
280
|
+
const epsilonValues = [
|
|
281
|
+
0.001, 0.002, 0.003, 0.004, 0.005, 0.006, 0.007, 0.008, 0.009,
|
|
282
|
+
0.01, 0.012, 0.015, 0.018, 0.02, 0.025, 0.03, 0.04, 0.05, 0.06, 0.07, 0.08, 0.09, 0.1
|
|
283
|
+
];
|
|
266
284
|
|
|
267
285
|
for (let attempt = 0; attempt < epsilonValues.length; attempt += 1) {
|
|
268
286
|
const epsilon = epsilonValues[attempt] * perimeter;
|
|
269
287
|
step = `contour_${i}_approxPolyDP_attempt_${attempt}`;
|
|
270
288
|
reportStage(step);
|
|
271
|
-
OpenCV.invoke('approxPolyDP',
|
|
289
|
+
OpenCV.invoke('approxPolyDP', contourToUse, approx, epsilon, true);
|
|
272
290
|
|
|
273
291
|
step = `contour_${i}_toJS_attempt_${attempt}`;
|
|
274
292
|
reportStage(step);
|