react-native-rectangle-doc-scanner 0.12.0 → 0.13.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.
@@ -154,9 +154,9 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
154
154
  const { value: perimeter } = react_native_fast_opencv_1.OpenCV.invoke('arcLength', contour, true);
155
155
  const approx = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.PointVector);
156
156
  let approxArray = [];
157
- let epsilonBase = 0.008 * perimeter;
158
- for (let attempt = 0; attempt < 8; attempt += 1) {
159
- const epsilon = epsilonBase * (1 + attempt * 0.75);
157
+ let epsilonBase = 0.006 * perimeter;
158
+ for (let attempt = 0; attempt < 10; attempt += 1) {
159
+ const epsilon = epsilonBase * (1 + attempt);
160
160
  step = `contour_${i}_approxPolyDP_attempt_${attempt}`;
161
161
  reportStage(step);
162
162
  react_native_fast_opencv_1.OpenCV.invoke('approxPolyDP', contour, approx, epsilon, true);
@@ -178,13 +178,21 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
178
178
  if (approxArray.length !== 4) {
179
179
  // fallback: boundingRect (axis-aligned) so we always have 4 points
180
180
  try {
181
- const { x: rectX, y: rectY, width: rectW, height: rectH } = react_native_fast_opencv_1.OpenCV.invoke('boundingRect', contour);
181
+ const rect = react_native_fast_opencv_1.OpenCV.invoke('boundingRect', contour);
182
+ const rectValue = rect?.value ?? rect;
183
+ const rectX = rectValue.x ?? rectValue?.topLeft?.x ?? 0;
184
+ const rectY = rectValue.y ?? rectValue?.topLeft?.y ?? 0;
185
+ const rectW = rectValue.width ?? rectValue?.size?.width ?? 0;
186
+ const rectH = rectValue.height ?? rectValue?.size?.height ?? 0;
182
187
  approxArray = [
183
188
  { x: rectX, y: rectY },
184
189
  { x: rectX + rectW, y: rectY },
185
190
  { x: rectX + rectW, y: rectY + rectH },
186
191
  { x: rectX, y: rectY + rectH },
187
192
  ];
193
+ if (__DEV__) {
194
+ console.log('[DocScanner] boundingRect fallback', approxArray);
195
+ }
188
196
  }
189
197
  catch (err) {
190
198
  if (__DEV__) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "0.12.0",
3
+ "version": "0.13.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -177,10 +177,10 @@ export const DocScanner: React.FC<Props> = ({
177
177
  const approx = OpenCV.createObject(ObjectType.PointVector);
178
178
 
179
179
  let approxArray: Array<{ x: number; y: number }> = [];
180
- let epsilonBase = 0.008 * perimeter;
180
+ let epsilonBase = 0.006 * perimeter;
181
181
 
182
- for (let attempt = 0; attempt < 8; attempt += 1) {
183
- const epsilon = epsilonBase * (1 + attempt * 0.75);
182
+ for (let attempt = 0; attempt < 10; attempt += 1) {
183
+ const epsilon = epsilonBase * (1 + attempt);
184
184
  step = `contour_${i}_approxPolyDP_attempt_${attempt}`;
185
185
  reportStage(step);
186
186
  OpenCV.invoke('approxPolyDP', contour, approx, epsilon, true);
@@ -207,13 +207,24 @@ export const DocScanner: React.FC<Props> = ({
207
207
  if (approxArray.length !== 4) {
208
208
  // fallback: boundingRect (axis-aligned) so we always have 4 points
209
209
  try {
210
- const { x: rectX, y: rectY, width: rectW, height: rectH } = OpenCV.invoke('boundingRect', contour);
210
+ const rect = OpenCV.invoke('boundingRect', contour);
211
+ const rectValue = rect?.value ?? rect;
212
+
213
+ const rectX = rectValue.x ?? rectValue?.topLeft?.x ?? 0;
214
+ const rectY = rectValue.y ?? rectValue?.topLeft?.y ?? 0;
215
+ const rectW = rectValue.width ?? rectValue?.size?.width ?? 0;
216
+ const rectH = rectValue.height ?? rectValue?.size?.height ?? 0;
217
+
211
218
  approxArray = [
212
219
  { x: rectX, y: rectY },
213
220
  { x: rectX + rectW, y: rectY },
214
221
  { x: rectX + rectW, y: rectY + rectH },
215
222
  { x: rectX, y: rectY + rectH },
216
223
  ];
224
+
225
+ if (__DEV__) {
226
+ console.log('[DocScanner] boundingRect fallback', approxArray);
227
+ }
217
228
  } catch (err) {
218
229
  if (__DEV__) {
219
230
  console.warn('[DocScanner] boundingRect fallback failed', err);