react-native-rectangle-doc-scanner 0.13.0 → 0.15.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 +37 -8
- package/package.json +1 -1
- package/src/DocScanner.tsx +42 -9
package/dist/DocScanner.js
CHANGED
|
@@ -177,26 +177,43 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
177
177
|
}
|
|
178
178
|
if (approxArray.length !== 4) {
|
|
179
179
|
// fallback: boundingRect (axis-aligned) so we always have 4 points
|
|
180
|
+
if (__DEV__) {
|
|
181
|
+
console.log('[DocScanner] attempting boundingRect fallback, current length:', approxArray.length);
|
|
182
|
+
}
|
|
180
183
|
try {
|
|
181
184
|
const rect = react_native_fast_opencv_1.OpenCV.invoke('boundingRect', contour);
|
|
182
185
|
const rectValue = rect?.value ?? rect;
|
|
186
|
+
if (__DEV__) {
|
|
187
|
+
console.log('[DocScanner] boundingRect result:', JSON.stringify(rectValue));
|
|
188
|
+
}
|
|
183
189
|
const rectX = rectValue.x ?? rectValue?.topLeft?.x ?? 0;
|
|
184
190
|
const rectY = rectValue.y ?? rectValue?.topLeft?.y ?? 0;
|
|
185
191
|
const rectW = rectValue.width ?? rectValue?.size?.width ?? 0;
|
|
186
192
|
const rectH = rectValue.height ?? rectValue?.size?.height ?? 0;
|
|
187
|
-
approxArray = [
|
|
188
|
-
{ x: rectX, y: rectY },
|
|
189
|
-
{ x: rectX + rectW, y: rectY },
|
|
190
|
-
{ x: rectX + rectW, y: rectY + rectH },
|
|
191
|
-
{ x: rectX, y: rectY + rectH },
|
|
192
|
-
];
|
|
193
193
|
if (__DEV__) {
|
|
194
|
-
console.log('[DocScanner]
|
|
194
|
+
console.log('[DocScanner] parsed rect:', { x: rectX, y: rectY, w: rectW, h: rectH });
|
|
195
|
+
}
|
|
196
|
+
// Validate that we have a valid rectangle
|
|
197
|
+
if (rectW > 0 && rectH > 0) {
|
|
198
|
+
approxArray = [
|
|
199
|
+
{ x: rectX, y: rectY },
|
|
200
|
+
{ x: rectX + rectW, y: rectY },
|
|
201
|
+
{ x: rectX + rectW, y: rectY + rectH },
|
|
202
|
+
{ x: rectX, y: rectY + rectH },
|
|
203
|
+
];
|
|
204
|
+
if (__DEV__) {
|
|
205
|
+
console.log('[DocScanner] boundingRect fallback success', approxArray);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
if (__DEV__) {
|
|
210
|
+
console.warn('[DocScanner] boundingRect has invalid dimensions');
|
|
211
|
+
}
|
|
195
212
|
}
|
|
196
213
|
}
|
|
197
214
|
catch (err) {
|
|
198
215
|
if (__DEV__) {
|
|
199
|
-
console.warn('[DocScanner] boundingRect fallback
|
|
216
|
+
console.warn('[DocScanner] boundingRect fallback exception', err);
|
|
200
217
|
}
|
|
201
218
|
}
|
|
202
219
|
}
|
|
@@ -205,6 +222,18 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
205
222
|
}
|
|
206
223
|
step = `contour_${i}_convex`;
|
|
207
224
|
reportStage(step);
|
|
225
|
+
// Validate points before processing
|
|
226
|
+
const isValidPoint = (pt) => {
|
|
227
|
+
return typeof pt.x === 'number' && typeof pt.y === 'number' &&
|
|
228
|
+
!isNaN(pt.x) && !isNaN(pt.y) &&
|
|
229
|
+
isFinite(pt.x) && isFinite(pt.y);
|
|
230
|
+
};
|
|
231
|
+
if (!approxArray.every(isValidPoint)) {
|
|
232
|
+
if (__DEV__) {
|
|
233
|
+
console.warn('[DocScanner] invalid points in approxArray', approxArray);
|
|
234
|
+
}
|
|
235
|
+
continue;
|
|
236
|
+
}
|
|
208
237
|
const points = approxArray.map((pt) => ({
|
|
209
238
|
x: pt.x / ratio,
|
|
210
239
|
y: pt.y / ratio,
|
package/package.json
CHANGED
package/src/DocScanner.tsx
CHANGED
|
@@ -206,28 +206,46 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
206
206
|
|
|
207
207
|
if (approxArray.length !== 4) {
|
|
208
208
|
// fallback: boundingRect (axis-aligned) so we always have 4 points
|
|
209
|
+
if (__DEV__) {
|
|
210
|
+
console.log('[DocScanner] attempting boundingRect fallback, current length:', approxArray.length);
|
|
211
|
+
}
|
|
209
212
|
try {
|
|
210
213
|
const rect = OpenCV.invoke('boundingRect', contour);
|
|
211
214
|
const rectValue = rect?.value ?? rect;
|
|
212
215
|
|
|
216
|
+
if (__DEV__) {
|
|
217
|
+
console.log('[DocScanner] boundingRect result:', JSON.stringify(rectValue));
|
|
218
|
+
}
|
|
219
|
+
|
|
213
220
|
const rectX = rectValue.x ?? rectValue?.topLeft?.x ?? 0;
|
|
214
221
|
const rectY = rectValue.y ?? rectValue?.topLeft?.y ?? 0;
|
|
215
222
|
const rectW = rectValue.width ?? rectValue?.size?.width ?? 0;
|
|
216
223
|
const rectH = rectValue.height ?? rectValue?.size?.height ?? 0;
|
|
217
224
|
|
|
218
|
-
approxArray = [
|
|
219
|
-
{ x: rectX, y: rectY },
|
|
220
|
-
{ x: rectX + rectW, y: rectY },
|
|
221
|
-
{ x: rectX + rectW, y: rectY + rectH },
|
|
222
|
-
{ x: rectX, y: rectY + rectH },
|
|
223
|
-
];
|
|
224
|
-
|
|
225
225
|
if (__DEV__) {
|
|
226
|
-
console.log('[DocScanner]
|
|
226
|
+
console.log('[DocScanner] parsed rect:', { x: rectX, y: rectY, w: rectW, h: rectH });
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
// Validate that we have a valid rectangle
|
|
230
|
+
if (rectW > 0 && rectH > 0) {
|
|
231
|
+
approxArray = [
|
|
232
|
+
{ x: rectX, y: rectY },
|
|
233
|
+
{ x: rectX + rectW, y: rectY },
|
|
234
|
+
{ x: rectX + rectW, y: rectY + rectH },
|
|
235
|
+
{ x: rectX, y: rectY + rectH },
|
|
236
|
+
];
|
|
237
|
+
|
|
238
|
+
if (__DEV__) {
|
|
239
|
+
console.log('[DocScanner] boundingRect fallback success', approxArray);
|
|
240
|
+
}
|
|
241
|
+
} else {
|
|
242
|
+
if (__DEV__) {
|
|
243
|
+
console.warn('[DocScanner] boundingRect has invalid dimensions');
|
|
244
|
+
}
|
|
227
245
|
}
|
|
228
246
|
} catch (err) {
|
|
229
247
|
if (__DEV__) {
|
|
230
|
-
console.warn('[DocScanner] boundingRect fallback
|
|
248
|
+
console.warn('[DocScanner] boundingRect fallback exception', err);
|
|
231
249
|
}
|
|
232
250
|
}
|
|
233
251
|
}
|
|
@@ -238,6 +256,21 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
238
256
|
|
|
239
257
|
step = `contour_${i}_convex`;
|
|
240
258
|
reportStage(step);
|
|
259
|
+
|
|
260
|
+
// Validate points before processing
|
|
261
|
+
const isValidPoint = (pt: { x: number; y: number }) => {
|
|
262
|
+
return typeof pt.x === 'number' && typeof pt.y === 'number' &&
|
|
263
|
+
!isNaN(pt.x) && !isNaN(pt.y) &&
|
|
264
|
+
isFinite(pt.x) && isFinite(pt.y);
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
if (!approxArray.every(isValidPoint)) {
|
|
268
|
+
if (__DEV__) {
|
|
269
|
+
console.warn('[DocScanner] invalid points in approxArray', approxArray);
|
|
270
|
+
}
|
|
271
|
+
continue;
|
|
272
|
+
}
|
|
273
|
+
|
|
241
274
|
const points: Point[] = approxArray.map((pt: { x: number; y: number }) => ({
|
|
242
275
|
x: pt.x / ratio,
|
|
243
276
|
y: pt.y / ratio,
|