rn-opencv-doc-perspective-correction 1.0.6 → 1.0.7

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 CHANGED
@@ -7,4 +7,8 @@ export declare class DocumentScanner {
7
7
  private static sortCorners;
8
8
  static detectPageCorners(imageBase64: string, onLog?: (msg: string) => void): Point[] | undefined;
9
9
  static applyPerspectiveCorrection(imageBase64: string, corners: Point[], onLog?: (msg: string) => void): string | undefined;
10
+ /**
11
+ * Xoay ảnh 90, -90 hoặc 180 độ
12
+ */
13
+ static rotateImage(imageBase64: string, angle: 90 | -90 | 180, onLog?: (msg: string) => void): string | undefined;
10
14
  }
package/dist/index.js CHANGED
@@ -146,5 +146,36 @@ class DocumentScanner {
146
146
  react_native_fast_opencv_1.OpenCV.clearBuffers();
147
147
  }
148
148
  }
149
+ /**
150
+ * Xoay ảnh 90, -90 hoặc 180 độ
151
+ */
152
+ static rotateImage(imageBase64, angle, onLog) {
153
+ let src = null;
154
+ let dst = null;
155
+ try {
156
+ src = react_native_fast_opencv_1.OpenCV.base64ToMat(imageBase64);
157
+ dst = react_native_fast_opencv_1.OpenCV.createObject(react_native_fast_opencv_1.ObjectType.Mat, 0, 0, react_native_fast_opencv_1.DataTypes.CV_8U);
158
+ let rotateCode = 0; // ROTATE_90_CLOCKWISE
159
+ if (angle === -90)
160
+ rotateCode = 2; // ROTATE_90_COUNTERCLOCKWISE
161
+ else if (angle === 180)
162
+ rotateCode = 1; // ROTATE_180
163
+ react_native_fast_opencv_1.OpenCV.invoke('rotate', src, dst, rotateCode);
164
+ const dstValue = react_native_fast_opencv_1.OpenCV.toJSValue(dst);
165
+ if (dstValue && dstValue.base64) {
166
+ return typeof dstValue.base64 === 'string' ? dstValue.base64 : String(dstValue.base64);
167
+ }
168
+ return undefined;
169
+ }
170
+ catch (e) {
171
+ console.error('Lỗi khi xoay ảnh (OpenCV):', e);
172
+ if (onLog)
173
+ onLog(`[OpenCV Rotate Error]: ${e.message}`);
174
+ return undefined;
175
+ }
176
+ finally {
177
+ react_native_fast_opencv_1.OpenCV.clearBuffers();
178
+ }
179
+ }
149
180
  }
150
181
  exports.DocumentScanner = DocumentScanner;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rn-opencv-doc-perspective-correction",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
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
@@ -175,5 +175,35 @@ export class DocumentScanner {
175
175
  OpenCV.clearBuffers();
176
176
  }
177
177
  }
178
+
179
+ /**
180
+ * Xoay ảnh 90, -90 hoặc 180 độ
181
+ */
182
+ public static rotateImage(imageBase64: string, angle: 90 | -90 | 180, onLog?: (msg: string) => void): string | undefined {
183
+ let src: OpenCVMat | null = null;
184
+ let dst: OpenCVMat | null = null;
185
+ try {
186
+ src = OpenCV.base64ToMat(imageBase64);
187
+ dst = OpenCV.createObject(ObjectType.Mat, 0, 0, DataTypes.CV_8U);
188
+
189
+ let rotateCode = 0; // ROTATE_90_CLOCKWISE
190
+ if (angle === -90) rotateCode = 2; // ROTATE_90_COUNTERCLOCKWISE
191
+ else if (angle === 180) rotateCode = 1; // ROTATE_180
192
+
193
+ OpenCV.invoke('rotate', src, dst, rotateCode);
194
+
195
+ const dstValue = OpenCV.toJSValue(dst);
196
+ if (dstValue && dstValue.base64) {
197
+ return typeof dstValue.base64 === 'string' ? dstValue.base64 : String(dstValue.base64);
198
+ }
199
+ return undefined;
200
+ } catch (e: any) {
201
+ console.error('Lỗi khi xoay ảnh (OpenCV):', e);
202
+ if (onLog) onLog(`[OpenCV Rotate Error]: ${e.message}`);
203
+ return undefined;
204
+ } finally {
205
+ OpenCV.clearBuffers();
206
+ }
207
+ }
178
208
  }
179
209