react-native-rectangle-doc-scanner 0.15.0 → 0.16.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 +9 -21
- package/package.json +1 -1
- package/src/DocScanner.tsx +9 -22
package/dist/DocScanner.js
CHANGED
|
@@ -177,22 +177,15 @@ 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
|
-
}
|
|
183
180
|
try {
|
|
184
181
|
const rect = react_native_fast_opencv_1.OpenCV.invoke('boundingRect', contour);
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
const
|
|
190
|
-
const
|
|
191
|
-
const
|
|
192
|
-
const rectH = rectValue.height ?? rectValue?.size?.height ?? 0;
|
|
193
|
-
if (__DEV__) {
|
|
194
|
-
console.log('[DocScanner] parsed rect:', { x: rectX, y: rectY, w: rectW, h: rectH });
|
|
195
|
-
}
|
|
182
|
+
// Convert the rect object to JS value to get actual coordinates
|
|
183
|
+
const rectJS = react_native_fast_opencv_1.OpenCV.toJSValue(rect);
|
|
184
|
+
const rectValue = rectJS?.value ?? rectJS;
|
|
185
|
+
const rectX = rectValue?.x ?? 0;
|
|
186
|
+
const rectY = rectValue?.y ?? 0;
|
|
187
|
+
const rectW = rectValue?.width ?? 0;
|
|
188
|
+
const rectH = rectValue?.height ?? 0;
|
|
196
189
|
// Validate that we have a valid rectangle
|
|
197
190
|
if (rectW > 0 && rectH > 0) {
|
|
198
191
|
approxArray = [
|
|
@@ -202,18 +195,13 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
202
195
|
{ x: rectX, y: rectY + rectH },
|
|
203
196
|
];
|
|
204
197
|
if (__DEV__) {
|
|
205
|
-
console.log('[DocScanner] boundingRect fallback
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
else {
|
|
209
|
-
if (__DEV__) {
|
|
210
|
-
console.warn('[DocScanner] boundingRect has invalid dimensions');
|
|
198
|
+
console.log('[DocScanner] using boundingRect fallback:', approxArray);
|
|
211
199
|
}
|
|
212
200
|
}
|
|
213
201
|
}
|
|
214
202
|
catch (err) {
|
|
215
203
|
if (__DEV__) {
|
|
216
|
-
console.warn('[DocScanner] boundingRect fallback
|
|
204
|
+
console.warn('[DocScanner] boundingRect fallback failed:', err);
|
|
217
205
|
}
|
|
218
206
|
}
|
|
219
207
|
}
|
package/package.json
CHANGED
package/src/DocScanner.tsx
CHANGED
|
@@ -206,25 +206,16 @@ 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
|
-
}
|
|
212
209
|
try {
|
|
213
210
|
const rect = OpenCV.invoke('boundingRect', contour);
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
console.log('[DocScanner] boundingRect result:', JSON.stringify(rectValue));
|
|
218
|
-
}
|
|
211
|
+
// Convert the rect object to JS value to get actual coordinates
|
|
212
|
+
const rectJS = OpenCV.toJSValue(rect);
|
|
213
|
+
const rectValue = rectJS?.value ?? rectJS;
|
|
219
214
|
|
|
220
|
-
const rectX = rectValue
|
|
221
|
-
const rectY = rectValue
|
|
222
|
-
const rectW = rectValue
|
|
223
|
-
const rectH = rectValue
|
|
224
|
-
|
|
225
|
-
if (__DEV__) {
|
|
226
|
-
console.log('[DocScanner] parsed rect:', { x: rectX, y: rectY, w: rectW, h: rectH });
|
|
227
|
-
}
|
|
215
|
+
const rectX = rectValue?.x ?? 0;
|
|
216
|
+
const rectY = rectValue?.y ?? 0;
|
|
217
|
+
const rectW = rectValue?.width ?? 0;
|
|
218
|
+
const rectH = rectValue?.height ?? 0;
|
|
228
219
|
|
|
229
220
|
// Validate that we have a valid rectangle
|
|
230
221
|
if (rectW > 0 && rectH > 0) {
|
|
@@ -236,16 +227,12 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
236
227
|
];
|
|
237
228
|
|
|
238
229
|
if (__DEV__) {
|
|
239
|
-
console.log('[DocScanner] boundingRect fallback
|
|
240
|
-
}
|
|
241
|
-
} else {
|
|
242
|
-
if (__DEV__) {
|
|
243
|
-
console.warn('[DocScanner] boundingRect has invalid dimensions');
|
|
230
|
+
console.log('[DocScanner] using boundingRect fallback:', approxArray);
|
|
244
231
|
}
|
|
245
232
|
}
|
|
246
233
|
} catch (err) {
|
|
247
234
|
if (__DEV__) {
|
|
248
|
-
console.warn('[DocScanner] boundingRect fallback
|
|
235
|
+
console.warn('[DocScanner] boundingRect fallback failed:', err);
|
|
249
236
|
}
|
|
250
237
|
}
|
|
251
238
|
}
|