rn-opencv-doc-perspective-correction 1.0.3 → 1.0.4
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/index.js +4 -14
- package/package.json +1 -1
- package/src/index.ts +12 -20
package/dist/index.js
CHANGED
|
@@ -53,22 +53,12 @@ class DocumentScanner {
|
|
|
53
53
|
const area = react_native_fast_opencv_1.OpenCV.invoke('contourArea', contour);
|
|
54
54
|
if (area > maxArea) {
|
|
55
55
|
const peri = react_native_fast_opencv_1.OpenCV.invoke('arcLength', contour, true);
|
|
56
|
-
const approx = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.
|
|
56
|
+
const approx = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.PointVector);
|
|
57
57
|
react_native_fast_opencv_1.OpenCV.invoke('approxPolyDP', contour, approx, 0.02 * peri, true);
|
|
58
|
-
const
|
|
59
|
-
if (
|
|
58
|
+
const approxJS = react_native_fast_opencv_1.OpenCV.toJSValue(approx);
|
|
59
|
+
if (approxJS && approxJS.array && approxJS.array.length === 4) {
|
|
60
60
|
maxArea = area;
|
|
61
|
-
|
|
62
|
-
for (let v = 0; v < 4; v++) {
|
|
63
|
-
try {
|
|
64
|
-
const pt = react_native_fast_opencv_1.OpenCV.invoke('row', approx, v);
|
|
65
|
-
if (pt && typeof pt === 'object' && 'x' in pt)
|
|
66
|
-
points.push(pt);
|
|
67
|
-
}
|
|
68
|
-
catch (err) { }
|
|
69
|
-
}
|
|
70
|
-
if (points.length === 4)
|
|
71
|
-
largestPoly = points;
|
|
61
|
+
largestPoly = approxJS.array;
|
|
72
62
|
}
|
|
73
63
|
}
|
|
74
64
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rn-opencv-doc-perspective-correction",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "A React Native library for document corner detection and perspective correction using react-native-fast-opencv",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
package/src/index.ts
CHANGED
|
@@ -68,21 +68,13 @@ export class DocumentScanner {
|
|
|
68
68
|
|
|
69
69
|
if (area > maxArea) {
|
|
70
70
|
const peri = OpenCV.invoke('arcLength', contour, true);
|
|
71
|
-
const approx = OpenCV.createObject(ObjectType.
|
|
71
|
+
const approx = OpenCV.createObject(ObjectType.PointVector);
|
|
72
72
|
OpenCV.invoke('approxPolyDP', contour, approx, 0.02 * peri, true);
|
|
73
73
|
|
|
74
|
-
const
|
|
75
|
-
if (
|
|
74
|
+
const approxJS = OpenCV.toJSValue(approx);
|
|
75
|
+
if (approxJS && approxJS.array && approxJS.array.length === 4) {
|
|
76
76
|
maxArea = area;
|
|
77
|
-
|
|
78
|
-
const points: Point[] = [];
|
|
79
|
-
for (let v = 0; v < 4; v++) {
|
|
80
|
-
try {
|
|
81
|
-
const pt = OpenCV.invoke('row', approx, v);
|
|
82
|
-
if (pt && typeof pt === 'object' && 'x' in pt) points.push(pt as Point);
|
|
83
|
-
} catch (err) { }
|
|
84
|
-
}
|
|
85
|
-
if (points.length === 4) largestPoly = points;
|
|
77
|
+
largestPoly = approxJS.array as Point[];
|
|
86
78
|
}
|
|
87
79
|
}
|
|
88
80
|
}
|
|
@@ -127,18 +119,18 @@ export class DocumentScanner {
|
|
|
127
119
|
|
|
128
120
|
const srcPoints = OpenCV.createObject(ObjectType.Point2fVector,
|
|
129
121
|
[
|
|
130
|
-
OpenCV.createObject(ObjectType.Point2f, tl.x, tl.y)
|
|
131
|
-
OpenCV.createObject(ObjectType.Point2f, tr.x, tr.y)
|
|
132
|
-
OpenCV.createObject(ObjectType.Point2f, br.x, br.y)
|
|
133
|
-
OpenCV.createObject(ObjectType.Point2f, bl.x, bl.y)
|
|
122
|
+
OpenCV.createObject(ObjectType.Point2f, tl.x, tl.y),
|
|
123
|
+
OpenCV.createObject(ObjectType.Point2f, tr.x, tr.y),
|
|
124
|
+
OpenCV.createObject(ObjectType.Point2f, br.x, br.y),
|
|
125
|
+
OpenCV.createObject(ObjectType.Point2f, bl.x, bl.y)
|
|
134
126
|
]
|
|
135
127
|
);
|
|
136
128
|
const dstPoints = OpenCV.createObject(ObjectType.Point2fVector,
|
|
137
129
|
[
|
|
138
|
-
OpenCV.createObject(ObjectType.Point2f, 0, 0)
|
|
139
|
-
OpenCV.createObject(ObjectType.Point2f, maxWidth - 1, 0)
|
|
140
|
-
OpenCV.createObject(ObjectType.Point2f, maxWidth - 1, maxHeight - 1)
|
|
141
|
-
OpenCV.createObject(ObjectType.Point2f, 0, maxHeight - 1)
|
|
130
|
+
OpenCV.createObject(ObjectType.Point2f, 0, 0),
|
|
131
|
+
OpenCV.createObject(ObjectType.Point2f, maxWidth - 1, 0),
|
|
132
|
+
OpenCV.createObject(ObjectType.Point2f, maxWidth - 1, maxHeight - 1),
|
|
133
|
+
OpenCV.createObject(ObjectType.Point2f, 0, maxHeight - 1)
|
|
142
134
|
]
|
|
143
135
|
);
|
|
144
136
|
|