react-native-rectangle-doc-scanner 0.10.0 → 0.11.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.
@@ -143,7 +143,10 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
143
143
  step = `contour_${i}_area`;
144
144
  reportStage(step);
145
145
  const { value: area } = react_native_fast_opencv_1.OpenCV.invoke('contourArea', contour, false);
146
- if (area < width * height * 0.02) {
146
+ if (__DEV__) {
147
+ console.log('[DocScanner] area ratio', area / (width * height));
148
+ }
149
+ if (area < width * height * 0.005) {
147
150
  continue;
148
151
  }
149
152
  step = `contour_${i}_arcLength`;
@@ -173,7 +176,22 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
173
176
  }
174
177
  }
175
178
  if (approxArray.length !== 4) {
176
- continue;
179
+ // fallback to minAreaRect -> boxPoints
180
+ try {
181
+ const minRect = react_native_fast_opencv_1.OpenCV.invoke('minAreaRect', contour);
182
+ const rectPoints = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.PointVector);
183
+ react_native_fast_opencv_1.OpenCV.invoke('boxPoints', minRect, rectPoints);
184
+ const rectValue = react_native_fast_opencv_1.OpenCV.toJSValue(rectPoints);
185
+ const rectArray = Array.isArray(rectValue?.array) ? rectValue.array : [];
186
+ if (rectArray.length === 4) {
187
+ approxArray = rectArray;
188
+ }
189
+ }
190
+ catch (err) {
191
+ if (__DEV__) {
192
+ console.warn('[DocScanner] minAreaRect fallback failed', err);
193
+ }
194
+ }
177
195
  }
178
196
  if (approxArray.length !== 4) {
179
197
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-rectangle-doc-scanner",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "repository": {
@@ -163,7 +163,11 @@ export const DocScanner: React.FC<Props> = ({
163
163
  reportStage(step);
164
164
  const { value: area } = OpenCV.invoke('contourArea', contour, false);
165
165
 
166
- if (area < width * height * 0.02) {
166
+ if (__DEV__) {
167
+ console.log('[DocScanner] area ratio', area / (width * height));
168
+ }
169
+
170
+ if (area < width * height * 0.005) {
167
171
  continue;
168
172
  }
169
173
 
@@ -201,7 +205,22 @@ export const DocScanner: React.FC<Props> = ({
201
205
  }
202
206
 
203
207
  if (approxArray.length !== 4) {
204
- continue;
208
+ // fallback to minAreaRect -> boxPoints
209
+ try {
210
+ const minRect = OpenCV.invoke('minAreaRect', contour);
211
+ const rectPoints = OpenCV.createObject(ObjectType.PointVector);
212
+ OpenCV.invoke('boxPoints', minRect, rectPoints);
213
+ const rectValue = OpenCV.toJSValue(rectPoints);
214
+ const rectArray = Array.isArray(rectValue?.array) ? rectValue.array : [];
215
+
216
+ if (rectArray.length === 4) {
217
+ approxArray = rectArray as Array<{ x: number; y: number }>;
218
+ }
219
+ } catch (err) {
220
+ if (__DEV__) {
221
+ console.warn('[DocScanner] minAreaRect fallback failed', err);
222
+ }
223
+ }
205
224
  }
206
225
 
207
226
  if (approxArray.length !== 4) {