react-native-rectangle-doc-scanner 0.9.0 → 0.10.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 +24 -9
- package/package.json +1 -1
- package/src/DocScanner.tsx +29 -10
package/dist/DocScanner.js
CHANGED
|
@@ -150,15 +150,30 @@ const DocScanner = ({ onCapture, overlayColor = '#e7a649', autoCapture = true, m
|
|
|
150
150
|
reportStage(step);
|
|
151
151
|
const { value: perimeter } = react_native_fast_opencv_1.OpenCV.invoke('arcLength', contour, true);
|
|
152
152
|
const approx = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.PointVector);
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
reportStage(
|
|
153
|
+
let approxArray = [];
|
|
154
|
+
let epsilonBase = 0.01 * perimeter;
|
|
155
|
+
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
156
|
+
const epsilon = epsilonBase * (1 + attempt * 0.5);
|
|
157
|
+
step = `contour_${i}_approxPolyDP_attempt_${attempt}`;
|
|
158
|
+
reportStage(step);
|
|
159
|
+
react_native_fast_opencv_1.OpenCV.invoke('approxPolyDP', contour, approx, epsilon, true);
|
|
160
|
+
step = `contour_${i}_toJS_attempt_${attempt}`;
|
|
161
|
+
reportStage(step);
|
|
162
|
+
const approxValue = react_native_fast_opencv_1.OpenCV.toJSValue(approx);
|
|
163
|
+
const candidate = Array.isArray(approxValue?.array) ? approxValue.array : [];
|
|
164
|
+
if (__DEV__) {
|
|
165
|
+
console.log('[DocScanner] approx length', candidate.length, 'epsilon', epsilon);
|
|
166
|
+
}
|
|
167
|
+
if (candidate.length === 4) {
|
|
168
|
+
approxArray = candidate;
|
|
169
|
+
break;
|
|
170
|
+
}
|
|
171
|
+
if (approxArray.length === 0 || Math.abs(candidate.length - 4) < Math.abs(approxArray.length - 4)) {
|
|
172
|
+
approxArray = candidate;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
if (approxArray.length !== 4) {
|
|
176
|
+
continue;
|
|
162
177
|
}
|
|
163
178
|
if (approxArray.length !== 4) {
|
|
164
179
|
continue;
|
package/package.json
CHANGED
package/src/DocScanner.tsx
CHANGED
|
@@ -172,17 +172,36 @@ export const DocScanner: React.FC<Props> = ({
|
|
|
172
172
|
const { value: perimeter } = OpenCV.invoke('arcLength', contour, true);
|
|
173
173
|
const approx = OpenCV.createObject(ObjectType.PointVector);
|
|
174
174
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
175
|
+
let approxArray: Array<{ x: number; y: number }> = [];
|
|
176
|
+
let epsilonBase = 0.01 * perimeter;
|
|
177
|
+
|
|
178
|
+
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
179
|
+
const epsilon = epsilonBase * (1 + attempt * 0.5);
|
|
180
|
+
step = `contour_${i}_approxPolyDP_attempt_${attempt}`;
|
|
181
|
+
reportStage(step);
|
|
182
|
+
OpenCV.invoke('approxPolyDP', contour, approx, epsilon, true);
|
|
183
|
+
|
|
184
|
+
step = `contour_${i}_toJS_attempt_${attempt}`;
|
|
185
|
+
reportStage(step);
|
|
186
|
+
const approxValue = OpenCV.toJSValue(approx);
|
|
187
|
+
const candidate = Array.isArray(approxValue?.array) ? approxValue.array : [];
|
|
188
|
+
|
|
189
|
+
if (__DEV__) {
|
|
190
|
+
console.log('[DocScanner] approx length', candidate.length, 'epsilon', epsilon);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
if (candidate.length === 4) {
|
|
194
|
+
approxArray = candidate as Array<{ x: number; y: number }>;
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
if (approxArray.length === 0 || Math.abs(candidate.length - 4) < Math.abs(approxArray.length - 4)) {
|
|
199
|
+
approxArray = candidate as Array<{ x: number; y: number }>;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
183
202
|
|
|
184
|
-
if (
|
|
185
|
-
|
|
203
|
+
if (approxArray.length !== 4) {
|
|
204
|
+
continue;
|
|
186
205
|
}
|
|
187
206
|
|
|
188
207
|
if (approxArray.length !== 4) {
|