rn-opencv-doc-perspective-correction 1.0.7 → 1.0.8
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.d.ts +3 -3
- package/dist/index.js +3 -15
- package/package.json +1 -1
- package/src/index.ts +4 -10
package/dist/index.d.ts
CHANGED
|
@@ -5,10 +5,10 @@ export type Point = {
|
|
|
5
5
|
export declare class DocumentScanner {
|
|
6
6
|
private static getDistance;
|
|
7
7
|
private static sortCorners;
|
|
8
|
-
static detectPageCorners(imageBase64: string
|
|
9
|
-
static applyPerspectiveCorrection(imageBase64: string, corners: Point[]
|
|
8
|
+
static detectPageCorners(imageBase64: string): Point[] | undefined;
|
|
9
|
+
static applyPerspectiveCorrection(imageBase64: string, corners: Point[]): string | undefined;
|
|
10
10
|
/**
|
|
11
11
|
* Xoay ảnh 90, -90 hoặc 180 độ
|
|
12
12
|
*/
|
|
13
|
-
static rotateImage(imageBase64: string, angle: 90 | -90 | 180
|
|
13
|
+
static rotateImage(imageBase64: string, angle: 90 | -90 | 180): string | undefined;
|
|
14
14
|
}
|
package/dist/index.js
CHANGED
|
@@ -17,7 +17,7 @@ class DocumentScanner {
|
|
|
17
17
|
return angleA - angleB;
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
|
-
static detectPageCorners(imageBase64
|
|
20
|
+
static detectPageCorners(imageBase64) {
|
|
21
21
|
let src = null;
|
|
22
22
|
let gray = null;
|
|
23
23
|
let blurred = null;
|
|
@@ -45,8 +45,6 @@ class DocumentScanner {
|
|
|
45
45
|
const contoursArray = (contoursJS === null || contoursJS === void 0 ? void 0 : contoursJS.array) || [];
|
|
46
46
|
const contoursSize = contoursArray.length;
|
|
47
47
|
if (contoursSize === 0) {
|
|
48
|
-
if (onLog)
|
|
49
|
-
onLog(`[OpenCV] Không tìm thấy contours.`);
|
|
50
48
|
return undefined;
|
|
51
49
|
}
|
|
52
50
|
// First pass: extract all areas to sort them and minimize JSI calls
|
|
@@ -76,10 +74,6 @@ class DocumentScanner {
|
|
|
76
74
|
break; // Stop at the first 4-point polygon like python script
|
|
77
75
|
}
|
|
78
76
|
}
|
|
79
|
-
const logMsg = `[OpenCV] Contours: ${contoursSize}. Metrics pass: ${contourMetrics.length}. Poly detect: ${largestPoly ? 'Thành công' : 'Thất bại'}.`;
|
|
80
|
-
console.log(logMsg);
|
|
81
|
-
if (onLog)
|
|
82
|
-
onLog(logMsg);
|
|
83
77
|
if (largestPoly && largestPoly.length === 4) {
|
|
84
78
|
return this.sortCorners(largestPoly);
|
|
85
79
|
}
|
|
@@ -87,15 +81,13 @@ class DocumentScanner {
|
|
|
87
81
|
}
|
|
88
82
|
catch (e) {
|
|
89
83
|
console.error('Lỗi khi dò tìm góc tài liệu (OpenCV):', e);
|
|
90
|
-
if (onLog)
|
|
91
|
-
onLog(`[OpenCV Corner Detection Error]: ${e.message}`);
|
|
92
84
|
throw new Error(`[OpenCV Corner Detection Error]: ${e.message}`);
|
|
93
85
|
}
|
|
94
86
|
finally {
|
|
95
87
|
react_native_fast_opencv_1.OpenCV.clearBuffers();
|
|
96
88
|
}
|
|
97
89
|
}
|
|
98
|
-
static applyPerspectiveCorrection(imageBase64, corners
|
|
90
|
+
static applyPerspectiveCorrection(imageBase64, corners) {
|
|
99
91
|
let src = null;
|
|
100
92
|
let dst = null;
|
|
101
93
|
try {
|
|
@@ -138,8 +130,6 @@ class DocumentScanner {
|
|
|
138
130
|
}
|
|
139
131
|
catch (e) {
|
|
140
132
|
console.error('Lỗi khi bóp phối cảnh tài liệu (OpenCV):', e);
|
|
141
|
-
if (onLog)
|
|
142
|
-
onLog(`[OpenCV Perspective Correction Error]: ${e.message || e}`);
|
|
143
133
|
return undefined;
|
|
144
134
|
}
|
|
145
135
|
finally {
|
|
@@ -149,7 +139,7 @@ class DocumentScanner {
|
|
|
149
139
|
/**
|
|
150
140
|
* Xoay ảnh 90, -90 hoặc 180 độ
|
|
151
141
|
*/
|
|
152
|
-
static rotateImage(imageBase64, angle
|
|
142
|
+
static rotateImage(imageBase64, angle) {
|
|
153
143
|
let src = null;
|
|
154
144
|
let dst = null;
|
|
155
145
|
try {
|
|
@@ -169,8 +159,6 @@ class DocumentScanner {
|
|
|
169
159
|
}
|
|
170
160
|
catch (e) {
|
|
171
161
|
console.error('Lỗi khi xoay ảnh (OpenCV):', e);
|
|
172
|
-
if (onLog)
|
|
173
|
-
onLog(`[OpenCV Rotate Error]: ${e.message}`);
|
|
174
162
|
return undefined;
|
|
175
163
|
}
|
|
176
164
|
finally {
|
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.8",
|
|
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
|
@@ -23,7 +23,7 @@ export class DocumentScanner {
|
|
|
23
23
|
});
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
public static detectPageCorners(imageBase64: string
|
|
26
|
+
public static detectPageCorners(imageBase64: string): Point[] | undefined {
|
|
27
27
|
let src: OpenCVMat | null = null;
|
|
28
28
|
let gray: OpenCVMat | null = null;
|
|
29
29
|
let blurred: OpenCVMat | null = null;
|
|
@@ -59,7 +59,6 @@ export class DocumentScanner {
|
|
|
59
59
|
const contoursSize = contoursArray.length;
|
|
60
60
|
|
|
61
61
|
if (contoursSize === 0) {
|
|
62
|
-
if (onLog) onLog(`[OpenCV] Không tìm thấy contours.`);
|
|
63
62
|
return undefined;
|
|
64
63
|
}
|
|
65
64
|
|
|
@@ -96,9 +95,7 @@ export class DocumentScanner {
|
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
|
|
100
|
-
console.log(logMsg);
|
|
101
|
-
if (onLog) onLog(logMsg);
|
|
98
|
+
|
|
102
99
|
|
|
103
100
|
if (largestPoly && largestPoly.length === 4) {
|
|
104
101
|
return this.sortCorners(largestPoly);
|
|
@@ -106,14 +103,13 @@ export class DocumentScanner {
|
|
|
106
103
|
return undefined;
|
|
107
104
|
} catch (e: any) {
|
|
108
105
|
console.error('Lỗi khi dò tìm góc tài liệu (OpenCV):', e);
|
|
109
|
-
if (onLog) onLog(`[OpenCV Corner Detection Error]: ${e.message}`);
|
|
110
106
|
throw new Error(`[OpenCV Corner Detection Error]: ${e.message}`);
|
|
111
107
|
} finally {
|
|
112
108
|
OpenCV.clearBuffers();
|
|
113
109
|
}
|
|
114
110
|
}
|
|
115
111
|
|
|
116
|
-
public static applyPerspectiveCorrection(imageBase64: string, corners: Point[]
|
|
112
|
+
public static applyPerspectiveCorrection(imageBase64: string, corners: Point[]): string | undefined {
|
|
117
113
|
let src: OpenCVMat | null = null;
|
|
118
114
|
let dst: OpenCVMat | null = null;
|
|
119
115
|
|
|
@@ -169,7 +165,6 @@ export class DocumentScanner {
|
|
|
169
165
|
return undefined;
|
|
170
166
|
} catch (e) {
|
|
171
167
|
console.error('Lỗi khi bóp phối cảnh tài liệu (OpenCV):', e);
|
|
172
|
-
if (onLog) onLog(`[OpenCV Perspective Correction Error]: ${(e as Error).message || e}`);
|
|
173
168
|
return undefined;
|
|
174
169
|
} finally {
|
|
175
170
|
OpenCV.clearBuffers();
|
|
@@ -179,7 +174,7 @@ export class DocumentScanner {
|
|
|
179
174
|
/**
|
|
180
175
|
* Xoay ảnh 90, -90 hoặc 180 độ
|
|
181
176
|
*/
|
|
182
|
-
public static rotateImage(imageBase64: string, angle: 90 | -90 | 180
|
|
177
|
+
public static rotateImage(imageBase64: string, angle: 90 | -90 | 180): string | undefined {
|
|
183
178
|
let src: OpenCVMat | null = null;
|
|
184
179
|
let dst: OpenCVMat | null = null;
|
|
185
180
|
try {
|
|
@@ -199,7 +194,6 @@ export class DocumentScanner {
|
|
|
199
194
|
return undefined;
|
|
200
195
|
} catch (e: any) {
|
|
201
196
|
console.error('Lỗi khi xoay ảnh (OpenCV):', e);
|
|
202
|
-
if (onLog) onLog(`[OpenCV Rotate Error]: ${e.message}`);
|
|
203
197
|
return undefined;
|
|
204
198
|
} finally {
|
|
205
199
|
OpenCV.clearBuffers();
|