react-native-rectangle-doc-scanner 3.101.0 → 3.102.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/FullDocScanner.js
CHANGED
|
@@ -373,18 +373,15 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
373
373
|
// 회전 각도 정규화 (0, 90, 180, 270)
|
|
374
374
|
const rotationNormalized = ((rotationDegrees % 360) + 360) % 360;
|
|
375
375
|
// OpenCV 회전 코드 매핑
|
|
376
|
-
// ROTATE_90_CLOCKWISE = 0
|
|
377
|
-
// ROTATE_180 = 1
|
|
378
|
-
// ROTATE_90_COUNTERCLOCKWISE = 2
|
|
379
376
|
let rotateCode;
|
|
380
377
|
if (rotationNormalized === 90) {
|
|
381
|
-
rotateCode =
|
|
378
|
+
rotateCode = react_native_fast_opencv_1.RotateFlags.ROTATE_90_CLOCKWISE;
|
|
382
379
|
}
|
|
383
380
|
else if (rotationNormalized === 180) {
|
|
384
|
-
rotateCode =
|
|
381
|
+
rotateCode = react_native_fast_opencv_1.RotateFlags.ROTATE_180;
|
|
385
382
|
}
|
|
386
383
|
else if (rotationNormalized === 270 || rotationNormalized === -90) {
|
|
387
|
-
rotateCode =
|
|
384
|
+
rotateCode = react_native_fast_opencv_1.RotateFlags.ROTATE_90_COUNTERCLOCKWISE;
|
|
388
385
|
}
|
|
389
386
|
else {
|
|
390
387
|
// 회전 없음
|
|
@@ -395,8 +392,18 @@ const FullDocScanner = ({ onResult, onClose, detectionConfig, overlayColor = '#3
|
|
|
395
392
|
setProcessing(false);
|
|
396
393
|
return;
|
|
397
394
|
}
|
|
395
|
+
// 이미지 파일을 Mat 객체로 로드
|
|
396
|
+
const srcMat = await react_native_fast_opencv_1.OpenCV.invoke('imread', croppedImageData.path);
|
|
397
|
+
// 빈 Mat 객체 생성 (회전된 이미지 저장용)
|
|
398
|
+
const dstMat = new react_native_fast_opencv_1.OpenCV.Mat();
|
|
398
399
|
// OpenCV로 이미지 회전
|
|
399
|
-
|
|
400
|
+
react_native_fast_opencv_1.OpenCV.invoke('rotate', srcMat, dstMat, rotateCode);
|
|
401
|
+
// 회전된 이미지를 임시 파일로 저장
|
|
402
|
+
const rotatedPath = `${react_native_fs_1.default.CachesDirectoryPath}/rotated_${Date.now()}.jpg`;
|
|
403
|
+
await react_native_fast_opencv_1.OpenCV.invoke('imwrite', rotatedPath, dstMat);
|
|
404
|
+
// Mat 객체 메모리 해제
|
|
405
|
+
srcMat.delete();
|
|
406
|
+
dstMat.delete();
|
|
400
407
|
// 회전된 이미지를 base64로 변환
|
|
401
408
|
const base64Data = await react_native_fs_1.default.readFile(rotatedPath, 'base64');
|
|
402
409
|
setProcessing(false);
|
package/package.json
CHANGED
package/src/FullDocScanner.tsx
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
import { launchImageLibrary } from 'react-native-image-picker';
|
|
13
13
|
import ImageCropPicker from 'react-native-image-crop-picker';
|
|
14
14
|
import RNFS from 'react-native-fs';
|
|
15
|
-
import {
|
|
15
|
+
import { OpenCV, RotateFlags } from 'react-native-fast-opencv';
|
|
16
16
|
import { DocScanner } from './DocScanner';
|
|
17
17
|
import type { CapturedDocument } from './types';
|
|
18
18
|
import type {
|
|
@@ -487,16 +487,13 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
487
487
|
const rotationNormalized = ((rotationDegrees % 360) + 360) % 360;
|
|
488
488
|
|
|
489
489
|
// OpenCV 회전 코드 매핑
|
|
490
|
-
|
|
491
|
-
// ROTATE_180 = 1
|
|
492
|
-
// ROTATE_90_COUNTERCLOCKWISE = 2
|
|
493
|
-
let rotateCode: number;
|
|
490
|
+
let rotateCode: RotateFlags;
|
|
494
491
|
if (rotationNormalized === 90) {
|
|
495
|
-
rotateCode =
|
|
492
|
+
rotateCode = RotateFlags.ROTATE_90_CLOCKWISE;
|
|
496
493
|
} else if (rotationNormalized === 180) {
|
|
497
|
-
rotateCode =
|
|
494
|
+
rotateCode = RotateFlags.ROTATE_180;
|
|
498
495
|
} else if (rotationNormalized === 270 || rotationNormalized === -90) {
|
|
499
|
-
rotateCode =
|
|
496
|
+
rotateCode = RotateFlags.ROTATE_90_COUNTERCLOCKWISE;
|
|
500
497
|
} else {
|
|
501
498
|
// 회전 없음
|
|
502
499
|
onResult({
|
|
@@ -507,8 +504,22 @@ export const FullDocScanner: React.FC<FullDocScannerProps> = ({
|
|
|
507
504
|
return;
|
|
508
505
|
}
|
|
509
506
|
|
|
507
|
+
// 이미지 파일을 Mat 객체로 로드
|
|
508
|
+
const srcMat = await OpenCV.invoke('imread', croppedImageData.path);
|
|
509
|
+
|
|
510
|
+
// 빈 Mat 객체 생성 (회전된 이미지 저장용)
|
|
511
|
+
const dstMat = new OpenCV.Mat();
|
|
512
|
+
|
|
510
513
|
// OpenCV로 이미지 회전
|
|
511
|
-
|
|
514
|
+
OpenCV.invoke('rotate', srcMat, dstMat, rotateCode);
|
|
515
|
+
|
|
516
|
+
// 회전된 이미지를 임시 파일로 저장
|
|
517
|
+
const rotatedPath = `${RNFS.CachesDirectoryPath}/rotated_${Date.now()}.jpg`;
|
|
518
|
+
await OpenCV.invoke('imwrite', rotatedPath, dstMat);
|
|
519
|
+
|
|
520
|
+
// Mat 객체 메모리 해제
|
|
521
|
+
srcMat.delete();
|
|
522
|
+
dstMat.delete();
|
|
512
523
|
|
|
513
524
|
// 회전된 이미지를 base64로 변환
|
|
514
525
|
const base64Data = await RNFS.readFile(rotatedPath, 'base64');
|
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
declare module 'react-native-fast-opencv' {
|
|
2
|
-
export
|
|
3
|
-
|
|
2
|
+
export enum RotateFlags {
|
|
3
|
+
ROTATE_90_CLOCKWISE = 0,
|
|
4
|
+
ROTATE_180 = 1,
|
|
5
|
+
ROTATE_90_COUNTERCLOCKWISE = 2
|
|
4
6
|
}
|
|
7
|
+
|
|
8
|
+
export class Mat {
|
|
9
|
+
delete(): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface OpenCVModel {
|
|
13
|
+
Mat: typeof Mat;
|
|
14
|
+
invoke(name: 'imread', path: string): Promise<Mat>;
|
|
15
|
+
invoke(name: 'imwrite', path: string, mat: Mat): Promise<void>;
|
|
16
|
+
invoke(name: 'rotate', src: Mat, dst: Mat, code: RotateFlags): void;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export const OpenCV: OpenCVModel;
|
|
5
20
|
}
|