@trustchex/react-native-sdk 1.267.0 → 1.354.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/lib/module/Screens/Dynamic/ContractAcceptanceScreen.js +8 -2
- package/lib/module/Screens/Dynamic/IdentityDocumentEIDScanningScreen.js +5 -1
- package/lib/module/Screens/Dynamic/IdentityDocumentScanningScreen.js +5 -1
- package/lib/module/Screens/Dynamic/LivenessDetectionScreen.js +29 -15
- package/lib/module/Screens/Static/OTPVerificationScreen.js +285 -0
- package/lib/module/Screens/Static/ResultScreen.js +90 -26
- package/lib/module/Screens/Static/VerificationSessionCheckScreen.js +48 -134
- package/lib/module/Shared/Components/DebugNavigationPanel.js +252 -0
- package/lib/module/Shared/Components/EIDScanner.js +142 -17
- package/lib/module/Shared/Components/FaceCamera.js +23 -11
- package/lib/module/Shared/Components/IdentityDocumentCamera.js +295 -44
- package/lib/module/Shared/Components/NavigationManager.js +19 -3
- package/lib/module/Shared/Config/camera-enhancement.config.js +58 -0
- package/lib/module/Shared/Contexts/AppContext.js +1 -0
- package/lib/module/Shared/Libs/camera.utils.js +221 -1
- package/lib/module/Shared/Libs/frame-enhancement.utils.js +133 -0
- package/lib/module/Shared/Libs/mrz.utils.js +98 -1
- package/lib/module/Translation/Resources/en.js +30 -0
- package/lib/module/Translation/Resources/tr.js +30 -0
- package/lib/module/Trustchex.js +49 -39
- package/lib/module/version.js +1 -1
- package/lib/typescript/src/Screens/Dynamic/ContractAcceptanceScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Dynamic/IdentityDocumentScanningScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Dynamic/LivenessDetectionScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Static/OTPVerificationScreen.d.ts +3 -0
- package/lib/typescript/src/Screens/Static/OTPVerificationScreen.d.ts.map +1 -0
- package/lib/typescript/src/Screens/Static/ResultScreen.d.ts.map +1 -1
- package/lib/typescript/src/Screens/Static/VerificationSessionCheckScreen.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/DebugNavigationPanel.d.ts +3 -0
- package/lib/typescript/src/Shared/Components/DebugNavigationPanel.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Components/EIDScanner.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/FaceCamera.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/IdentityDocumentCamera.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Components/NavigationManager.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Config/camera-enhancement.config.d.ts +54 -0
- package/lib/typescript/src/Shared/Config/camera-enhancement.config.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Contexts/AppContext.d.ts +2 -0
- package/lib/typescript/src/Shared/Contexts/AppContext.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/camera.utils.d.ts +65 -1
- package/lib/typescript/src/Shared/Libs/camera.utils.d.ts.map +1 -1
- package/lib/typescript/src/Shared/Libs/frame-enhancement.utils.d.ts +25 -0
- package/lib/typescript/src/Shared/Libs/frame-enhancement.utils.d.ts.map +1 -0
- package/lib/typescript/src/Shared/Libs/mrz.utils.d.ts.map +1 -1
- package/lib/typescript/src/Translation/Resources/en.d.ts +30 -0
- package/lib/typescript/src/Translation/Resources/en.d.ts.map +1 -1
- package/lib/typescript/src/Translation/Resources/tr.d.ts +30 -0
- package/lib/typescript/src/Translation/Resources/tr.d.ts.map +1 -1
- package/lib/typescript/src/Trustchex.d.ts.map +1 -1
- package/lib/typescript/src/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/Screens/Dynamic/ContractAcceptanceScreen.tsx +6 -2
- package/src/Screens/Dynamic/IdentityDocumentEIDScanningScreen.tsx +3 -1
- package/src/Screens/Dynamic/IdentityDocumentScanningScreen.tsx +3 -1
- package/src/Screens/Dynamic/LivenessDetectionScreen.tsx +27 -17
- package/src/Screens/Static/OTPVerificationScreen.tsx +379 -0
- package/src/Screens/Static/ResultScreen.tsx +160 -101
- package/src/Screens/Static/VerificationSessionCheckScreen.tsx +51 -196
- package/src/Shared/Components/DebugNavigationPanel.tsx +262 -0
- package/src/Shared/Components/EIDScanner.tsx +144 -19
- package/src/Shared/Components/FaceCamera.tsx +38 -21
- package/src/Shared/Components/IdentityDocumentCamera.tsx +399 -101
- package/src/Shared/Components/NavigationManager.tsx +19 -3
- package/src/Shared/Config/camera-enhancement.config.ts +46 -0
- package/src/Shared/Contexts/AppContext.ts +3 -0
- package/src/Shared/Libs/camera.utils.ts +240 -1
- package/src/Shared/Libs/frame-enhancement.utils.ts +217 -0
- package/src/Shared/Libs/mrz.utils.ts +78 -1
- package/src/Translation/Resources/en.ts +30 -0
- package/src/Translation/Resources/tr.ts +30 -0
- package/src/Trustchex.tsx +58 -46
- package/src/version.ts +1 -1
|
@@ -1,5 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Check if frame is blurry using Laplacian variance
|
|
5
|
+
* Uses both horizontal and vertical gradients for more accurate blur detection
|
|
6
|
+
* Lower variance indicates a blurrier image
|
|
7
|
+
* @param frame - The camera frame to analyze
|
|
8
|
+
* @param threshold - Variance threshold below which image is considered blurry (default: 10)
|
|
9
|
+
* @returns true if image is blurry, false otherwise
|
|
10
|
+
*/
|
|
11
|
+
const isBlurry = (frame, threshold = 10) => {
|
|
12
|
+
'worklet';
|
|
13
|
+
|
|
14
|
+
const buffer = frame.toArrayBuffer();
|
|
15
|
+
const data = new Uint8Array(buffer);
|
|
16
|
+
const width = frame.width;
|
|
17
|
+
const height = frame.height;
|
|
18
|
+
let sum = 0;
|
|
19
|
+
let sumSq = 0;
|
|
20
|
+
let count = 0;
|
|
21
|
+
|
|
22
|
+
// Sample central 50% region (matching Flutter algorithm)
|
|
23
|
+
const startY = Math.floor(height / 4);
|
|
24
|
+
const endY = Math.floor(3 * height / 4) - 1;
|
|
25
|
+
const startX = Math.floor(width / 4);
|
|
26
|
+
const endX = Math.floor(3 * width / 4) - 1;
|
|
27
|
+
|
|
28
|
+
// Sample at 5-pixel intervals for better accuracy (matching Flutter)
|
|
29
|
+
for (let y = startY; y < endY; y += 5) {
|
|
30
|
+
for (let x = startX; x < endX; x += 5) {
|
|
31
|
+
const idx = y * width + x;
|
|
32
|
+
const idxRight = idx + 1;
|
|
33
|
+
const idxDown = idx + width;
|
|
34
|
+
|
|
35
|
+
// Check bounds for both horizontal and vertical neighbors
|
|
36
|
+
if (idxRight < data.length && idxDown < data.length && data[idx] !== undefined && data[idxRight] !== undefined && data[idxDown] !== undefined) {
|
|
37
|
+
// Horizontal gradient
|
|
38
|
+
const diffH = Math.abs(data[idx] - data[idxRight]);
|
|
39
|
+
// Vertical gradient
|
|
40
|
+
const diffV = Math.abs(data[idx] - data[idxDown]);
|
|
41
|
+
// Combined Laplacian-like measure
|
|
42
|
+
const laplacian = diffH + diffV;
|
|
43
|
+
sum += laplacian;
|
|
44
|
+
sumSq += laplacian * laplacian;
|
|
45
|
+
count++;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (count === 0) return false;
|
|
50
|
+
|
|
51
|
+
// Calculate variance: E[X²] - E[X]²
|
|
52
|
+
const mean = sum / count;
|
|
53
|
+
const variance = sumSq / count - mean * mean;
|
|
54
|
+
return variance < threshold;
|
|
55
|
+
};
|
|
56
|
+
|
|
3
57
|
/**
|
|
4
58
|
* Get average brightness for entire frame (center area)
|
|
5
59
|
*/
|
|
@@ -85,4 +139,170 @@ const isCircularRegionBright = (frame, circleRect, threshold = 60) => {
|
|
|
85
139
|
|
|
86
140
|
return getCircularRegionBrightness(frame, circleRect) > threshold;
|
|
87
141
|
};
|
|
88
|
-
|
|
142
|
+
|
|
143
|
+
/**
|
|
144
|
+
* Get average brightness for a specific rectangular region
|
|
145
|
+
*/
|
|
146
|
+
const getRegionBrightness = (frame, bounds) => {
|
|
147
|
+
'worklet';
|
|
148
|
+
|
|
149
|
+
const buffer = frame.toArrayBuffer();
|
|
150
|
+
const data = new Uint8Array(buffer);
|
|
151
|
+
const width = frame.width;
|
|
152
|
+
const height = frame.height;
|
|
153
|
+
const minX = Math.max(0, Math.floor(bounds.minX));
|
|
154
|
+
const maxX = Math.min(width - 1, Math.floor(bounds.minX + bounds.width));
|
|
155
|
+
const minY = Math.max(0, Math.floor(bounds.minY));
|
|
156
|
+
const maxY = Math.min(height - 1, Math.floor(bounds.minY + bounds.height));
|
|
157
|
+
let luminanceSum = 0;
|
|
158
|
+
let pixelCount = 0;
|
|
159
|
+
for (let y = minY; y <= maxY; y++) {
|
|
160
|
+
for (let x = minX; x <= maxX; x++) {
|
|
161
|
+
const index = y * width + x;
|
|
162
|
+
if (data[index] !== undefined) {
|
|
163
|
+
luminanceSum += data[index];
|
|
164
|
+
pixelCount++;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return pixelCount > 0 ? luminanceSum / pixelCount : 0;
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Calculate adaptive exposure step based on distance from target brightness
|
|
173
|
+
* Uses smooth scaling to prevent abrupt exposure changes that could cause dark frames
|
|
174
|
+
*/
|
|
175
|
+
const calculateExposureStep = (currentBrightness, targetBrightness) => {
|
|
176
|
+
'worklet';
|
|
177
|
+
|
|
178
|
+
const difference = Math.abs(targetBrightness - currentBrightness);
|
|
179
|
+
// Use smaller steps for smoother transitions: max 2, min 1
|
|
180
|
+
// Use floor + 1 to ensure at least step of 1 and prevent over-correction
|
|
181
|
+
const step = Math.min(2, Math.max(1, Math.floor(difference / 25)));
|
|
182
|
+
return step;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* Get the center point of the scan area
|
|
187
|
+
* Scan area is typically 36%-64% of vertical space
|
|
188
|
+
*/
|
|
189
|
+
const getScanAreaCenterPoint = (width, height) => {
|
|
190
|
+
const scanAreaTop = height * 0.36;
|
|
191
|
+
const scanAreaBottom = height * 0.64;
|
|
192
|
+
const scanAreaCenterY = (scanAreaTop + scanAreaBottom) / 2;
|
|
193
|
+
const scanAreaCenterX = width / 2;
|
|
194
|
+
return {
|
|
195
|
+
x: scanAreaCenterX,
|
|
196
|
+
y: scanAreaCenterY
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/**
|
|
201
|
+
* Document dimensions (in mm) for reference
|
|
202
|
+
*/
|
|
203
|
+
const DOCUMENT_DIMENSIONS = {
|
|
204
|
+
ID_CARD: {
|
|
205
|
+
width: 85.6,
|
|
206
|
+
height: 53.98,
|
|
207
|
+
ratio: 1.586
|
|
208
|
+
},
|
|
209
|
+
PASSPORT: {
|
|
210
|
+
width: 125,
|
|
211
|
+
height: 88,
|
|
212
|
+
ratio: 1.42
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* Detected document information
|
|
218
|
+
*/
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Detect document contours and estimate document type based on aspect ratio
|
|
222
|
+
* This is a simplified detection that looks for rectangular contours in the scan area
|
|
223
|
+
* @param frame - The camera frame to analyze
|
|
224
|
+
* @param scanAreaBounds - The bounds of the scan area {x, y, width, height}
|
|
225
|
+
* @returns Detected document info or null if no document detected
|
|
226
|
+
*/
|
|
227
|
+
const detectDocumentInFrame = (frame, scanAreaBounds) => {
|
|
228
|
+
'worklet';
|
|
229
|
+
|
|
230
|
+
// For now, we'll use a simple edge-based detection
|
|
231
|
+
// In production, this would integrate with OpenCV findContours
|
|
232
|
+
// This is a placeholder that estimates based on brightness patterns
|
|
233
|
+
const buffer = frame.toArrayBuffer();
|
|
234
|
+
const data = new Uint8Array(buffer);
|
|
235
|
+
const frameWidth = frame.width;
|
|
236
|
+
const frameHeight = frame.height;
|
|
237
|
+
|
|
238
|
+
// Sample edges of scan area to detect document boundaries
|
|
239
|
+
const scanX = Math.floor(scanAreaBounds.x * frameWidth);
|
|
240
|
+
const scanY = Math.floor(scanAreaBounds.y * frameHeight);
|
|
241
|
+
const scanWidth = Math.floor(scanAreaBounds.width * frameWidth);
|
|
242
|
+
const scanHeight = Math.floor(scanAreaBounds.height * frameHeight);
|
|
243
|
+
|
|
244
|
+
// Calculate average brightness in scan area to detect presence of document
|
|
245
|
+
// Documents typically have good contrast against backgrounds
|
|
246
|
+
let totalBrightness = 0;
|
|
247
|
+
let sampleCount = 0;
|
|
248
|
+
const sampleStep = 20; // Sample every 20 pixels for performance
|
|
249
|
+
|
|
250
|
+
// Sample brightness across the scan area
|
|
251
|
+
for (let y = scanY; y < scanY + scanHeight; y += sampleStep) {
|
|
252
|
+
for (let x = scanX; x < scanX + scanWidth; x += sampleStep) {
|
|
253
|
+
const idx = y * frameWidth + x;
|
|
254
|
+
if (idx >= 0 && idx < data.length) {
|
|
255
|
+
totalBrightness += data[idx];
|
|
256
|
+
sampleCount++;
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
const avgBrightness = sampleCount > 0 ? totalBrightness / sampleCount : 0;
|
|
261
|
+
|
|
262
|
+
// Calculate standard deviation to measure contrast
|
|
263
|
+
let variance = 0;
|
|
264
|
+
for (let y = scanY; y < scanY + scanHeight; y += sampleStep) {
|
|
265
|
+
for (let x = scanX; x < scanX + scanWidth; x += sampleStep) {
|
|
266
|
+
const idx = y * frameWidth + x;
|
|
267
|
+
if (idx >= 0 && idx < data.length) {
|
|
268
|
+
const diff = data[idx] - avgBrightness;
|
|
269
|
+
variance += diff * diff;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
const stdDev = sampleCount > 0 ? Math.sqrt(variance / sampleCount) : 0;
|
|
274
|
+
|
|
275
|
+
// Document is present if there's ANY reasonable content in scan area
|
|
276
|
+
// Lower threshold: stdDev > 10 indicates some content (not blank surface)
|
|
277
|
+
// Brightness between 20-240 covers most lighting conditions
|
|
278
|
+
const documentPresent = stdDev > 10 && avgBrightness > 20 && avgBrightness < 240;
|
|
279
|
+
if (!documentPresent) {
|
|
280
|
+
return null;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
// Default to ID_CARD since scan area matches ID card proportions
|
|
284
|
+
// Passport detection would require actual contour detection
|
|
285
|
+
const type = 'ID_CARD';
|
|
286
|
+
const confidence = Math.min(1, stdDev / 50);
|
|
287
|
+
|
|
288
|
+
// Calculate how much of frame the document occupies
|
|
289
|
+
const framePercentage = scanWidth * scanHeight / (frameWidth * frameHeight);
|
|
290
|
+
const aspectRatio = scanWidth / scanHeight;
|
|
291
|
+
|
|
292
|
+
// Determine size feedback based on contrast level
|
|
293
|
+
// Higher contrast usually means document is closer/larger
|
|
294
|
+
let size = 'GOOD';
|
|
295
|
+
if (stdDev < 25) {
|
|
296
|
+
size = 'TOO_SMALL'; // Low contrast - probably far away
|
|
297
|
+
} else if (stdDev > 80) {
|
|
298
|
+
size = 'TOO_LARGE'; // Very high contrast - probably too close
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
type,
|
|
302
|
+
size,
|
|
303
|
+
aspectRatio,
|
|
304
|
+
confidence: Math.min(1, confidence),
|
|
305
|
+
framePercentage
|
|
306
|
+
};
|
|
307
|
+
};
|
|
308
|
+
export { isBlurry, isFrameBright, getAverageBrightness, getCircularRegionBrightness, isCircularRegionBright, getRegionBrightness, calculateExposureStep, getScanAreaCenterPoint, detectDocumentInFrame, DOCUMENT_DIMENSIONS };
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { ColorConversionCodes, DataTypes, ObjectType, OpenCV } from 'react-native-fast-opencv';
|
|
4
|
+
import { ENHANCEMENT_CONFIG } from "../Config/camera-enhancement.config.js";
|
|
5
|
+
|
|
6
|
+
// Cast OpenCV for methods not in type definitions
|
|
7
|
+
const OpenCVAny = OpenCV;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Convert YUV frame to BGR Mat for OpenCV processing
|
|
11
|
+
*/
|
|
12
|
+
const convertYUVToBGR = frame => {
|
|
13
|
+
'worklet';
|
|
14
|
+
|
|
15
|
+
const buffer = frame.toArrayBuffer();
|
|
16
|
+
const data = new Uint8Array(buffer);
|
|
17
|
+
const width = frame.width;
|
|
18
|
+
const height = frame.height;
|
|
19
|
+
|
|
20
|
+
// Create YUV Mat from frame buffer
|
|
21
|
+
const yuvMat = OpenCV.createObject(ObjectType.Mat, height + height / 2, width, DataTypes.CV_8UC1);
|
|
22
|
+
|
|
23
|
+
// Copy frame data to YUV Mat
|
|
24
|
+
OpenCVAny.invoke('matSetData', yuvMat, data);
|
|
25
|
+
|
|
26
|
+
// Convert YUV to BGR
|
|
27
|
+
const bgrMat = OpenCV.createObject(ObjectType.Mat, height, width, DataTypes.CV_8UC3);
|
|
28
|
+
OpenCV.invoke('cvtColor', yuvMat, bgrMat, ColorConversionCodes.COLOR_YUV2BGR_NV21);
|
|
29
|
+
return bgrMat;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Apply CLAHE (Contrast Limited Adaptive Histogram Equalization) to enhance frame
|
|
34
|
+
* This improves text and face recognition in varying lighting conditions
|
|
35
|
+
*/
|
|
36
|
+
const enhanceFrameForOCR = (frame, options) => {
|
|
37
|
+
'worklet';
|
|
38
|
+
|
|
39
|
+
const clipLimit = options?.clipLimit ?? ENHANCEMENT_CONFIG.contrast.clahe.clipLimit;
|
|
40
|
+
const tileGridSize = options?.tileGridSize ?? ENHANCEMENT_CONFIG.contrast.clahe.tileGridSize[0];
|
|
41
|
+
try {
|
|
42
|
+
// 1. Convert YUV to BGR
|
|
43
|
+
const bgrMat = convertYUVToBGR(frame);
|
|
44
|
+
|
|
45
|
+
// 2. Convert BGR to LAB color space (better for luminance enhancement)
|
|
46
|
+
const labMat = OpenCV.createObject(ObjectType.Mat, frame.height, frame.width, DataTypes.CV_8UC3);
|
|
47
|
+
OpenCV.invoke('cvtColor', bgrMat, labMat, ColorConversionCodes.COLOR_BGR2Lab);
|
|
48
|
+
|
|
49
|
+
// 3. Split LAB channels
|
|
50
|
+
const channels = OpenCVAny.invoke('split', labMat);
|
|
51
|
+
const lChannel = channels[0]; // Luminance channel
|
|
52
|
+
const aChannel = channels[1]; // a channel
|
|
53
|
+
const bChannel = channels[2]; // b channel
|
|
54
|
+
|
|
55
|
+
// 4. Apply CLAHE to L channel
|
|
56
|
+
const clahe = OpenCVAny.invoke('createCLAHE', clipLimit, [tileGridSize, tileGridSize]);
|
|
57
|
+
const enhancedL = OpenCV.createObject(ObjectType.Mat, frame.height, frame.width, DataTypes.CV_8UC1);
|
|
58
|
+
OpenCVAny.invoke('apply', clahe, lChannel, enhancedL);
|
|
59
|
+
|
|
60
|
+
// 5. Merge enhanced L channel with original a and b channels
|
|
61
|
+
const enhancedLab = OpenCVAny.invoke('merge', [enhancedL, aChannel, bChannel]);
|
|
62
|
+
|
|
63
|
+
// 6. Convert back to BGR
|
|
64
|
+
const enhancedBGR = OpenCV.createObject(ObjectType.Mat, frame.height, frame.width, DataTypes.CV_8UC3);
|
|
65
|
+
OpenCV.invoke('cvtColor', enhancedLab, enhancedBGR, ColorConversionCodes.COLOR_Lab2BGR);
|
|
66
|
+
|
|
67
|
+
// Cleanup intermediate Mats
|
|
68
|
+
OpenCVAny.invoke('delete', bgrMat);
|
|
69
|
+
OpenCVAny.invoke('delete', labMat);
|
|
70
|
+
OpenCVAny.invoke('delete', lChannel);
|
|
71
|
+
OpenCVAny.invoke('delete', aChannel);
|
|
72
|
+
OpenCVAny.invoke('delete', bChannel);
|
|
73
|
+
OpenCVAny.invoke('delete', enhancedL);
|
|
74
|
+
OpenCVAny.invoke('delete', enhancedLab);
|
|
75
|
+
return enhancedBGR;
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.warn('Error enhancing frame:', error);
|
|
78
|
+
// Return original frame converted to BGR if enhancement fails
|
|
79
|
+
return convertYUVToBGR(frame);
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Apply sharpening to enhance text clarity
|
|
85
|
+
* Uses unsharp mask technique
|
|
86
|
+
*/
|
|
87
|
+
const sharpenForText = (mat, amount = 1.5) => {
|
|
88
|
+
'worklet';
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
const blurred = OpenCV.createObject(ObjectType.Mat, 0, 0, DataTypes.CV_8UC3);
|
|
92
|
+
|
|
93
|
+
// Apply Gaussian blur
|
|
94
|
+
OpenCVAny.invoke('GaussianBlur', mat, blurred, [0, 0], 3.0);
|
|
95
|
+
|
|
96
|
+
// Create sharpened image: original * (1 + amount) - blurred * amount
|
|
97
|
+
const sharpened = OpenCV.createObject(ObjectType.Mat, 0, 0, DataTypes.CV_8UC3);
|
|
98
|
+
OpenCV.invoke('addWeighted', mat, 1.0 + amount, blurred, -amount, 0, sharpened);
|
|
99
|
+
|
|
100
|
+
// Cleanup
|
|
101
|
+
OpenCVAny.invoke('delete', blurred);
|
|
102
|
+
return sharpened;
|
|
103
|
+
} catch (error) {
|
|
104
|
+
console.warn('Error sharpening frame:', error);
|
|
105
|
+
return mat;
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Determine if frame should be enhanced based on current scanning state
|
|
111
|
+
*/
|
|
112
|
+
const shouldEnhanceFrame = (nextStep, detectedFaces, mrzRetryCount) => {
|
|
113
|
+
'worklet';
|
|
114
|
+
|
|
115
|
+
const config = ENHANCEMENT_CONFIG.contrast.applyWhen;
|
|
116
|
+
|
|
117
|
+
// Always enhance for document back side (MRZ scanning)
|
|
118
|
+
if (config.documentBackSide && nextStep === 'SCAN_ID_BACK') {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Enhance if faces are failing to detect on front/passport
|
|
123
|
+
if (config.faceFailing && nextStep === 'SCAN_ID_FRONT_OR_PASSPORT' && detectedFaces === 0) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// Enhance if MRZ detection is failing
|
|
128
|
+
if (config.mrzFailing && mrzRetryCount >= config.retryThreshold) {
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
return false;
|
|
132
|
+
};
|
|
133
|
+
export { convertYUVToBGR, enhanceFrameForOCR, sharpenForText, shouldEnhanceFrame };
|
|
@@ -53,13 +53,110 @@ const getMRZText = fixedText => {
|
|
|
53
53
|
}
|
|
54
54
|
return null;
|
|
55
55
|
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Apply common OCR corrections for MRZ text
|
|
59
|
+
* Common confusions: 0/O, 1/I, 8/B, 5/S, 2/Z
|
|
60
|
+
*/
|
|
61
|
+
const applyOCRCorrections = mrzText => {
|
|
62
|
+
const corrections = [];
|
|
63
|
+
|
|
64
|
+
// Common OCR substitutions to try
|
|
65
|
+
// In MRZ: letters should be in name fields, numbers in date/checksum fields
|
|
66
|
+
const substitutions = [
|
|
67
|
+
// Try replacing O with 0 in numeric positions (dates, checksums)
|
|
68
|
+
{
|
|
69
|
+
from: /O/g,
|
|
70
|
+
to: '0'
|
|
71
|
+
},
|
|
72
|
+
// Try replacing 0 with O in alphabetic positions (names, country codes)
|
|
73
|
+
{
|
|
74
|
+
from: /0/g,
|
|
75
|
+
to: 'O'
|
|
76
|
+
},
|
|
77
|
+
// I and 1 confusion
|
|
78
|
+
{
|
|
79
|
+
from: /I(?=\d)/g,
|
|
80
|
+
to: '1'
|
|
81
|
+
},
|
|
82
|
+
// I followed by digit -> likely 1
|
|
83
|
+
{
|
|
84
|
+
from: /1(?=[A-Z])/g,
|
|
85
|
+
to: 'I'
|
|
86
|
+
},
|
|
87
|
+
// 1 followed by letter -> likely I
|
|
88
|
+
// B and 8 confusion
|
|
89
|
+
{
|
|
90
|
+
from: /B(?=\d)/g,
|
|
91
|
+
to: '8'
|
|
92
|
+
}, {
|
|
93
|
+
from: /8(?=[A-Z])/g,
|
|
94
|
+
to: 'B'
|
|
95
|
+
},
|
|
96
|
+
// S and 5 confusion
|
|
97
|
+
{
|
|
98
|
+
from: /S(?=\d)/g,
|
|
99
|
+
to: '5'
|
|
100
|
+
}, {
|
|
101
|
+
from: /5(?=[A-Z])/g,
|
|
102
|
+
to: 'S'
|
|
103
|
+
},
|
|
104
|
+
// Z and 2 confusion
|
|
105
|
+
{
|
|
106
|
+
from: /Z(?=\d)/g,
|
|
107
|
+
to: '2'
|
|
108
|
+
}, {
|
|
109
|
+
from: /2(?=[A-Z])/g,
|
|
110
|
+
to: 'Z'
|
|
111
|
+
}];
|
|
112
|
+
for (const sub of substitutions) {
|
|
113
|
+
const corrected = mrzText.replace(sub.from, sub.to);
|
|
114
|
+
if (corrected !== mrzText) {
|
|
115
|
+
corrections.push(corrected);
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return corrections;
|
|
119
|
+
};
|
|
56
120
|
const getMRZData = ocrText => {
|
|
57
121
|
const fixedText = fixMRZ(ocrText);
|
|
58
122
|
const mrzText = getMRZText(fixedText);
|
|
59
123
|
if (mrzText) {
|
|
60
|
-
|
|
124
|
+
// First attempt with original text
|
|
125
|
+
let parsedResult = parse(mrzText, {
|
|
61
126
|
autocorrect: true
|
|
62
127
|
});
|
|
128
|
+
|
|
129
|
+
// Check if parse is valid with all required fields
|
|
130
|
+
const isValidParse = result => {
|
|
131
|
+
return result.valid && result.fields.firstName && result.fields.lastName && result.fields.birthDate && result.fields.expirationDate && result.fields.documentNumber && result.fields.issuingState;
|
|
132
|
+
};
|
|
133
|
+
if (isValidParse(parsedResult)) {
|
|
134
|
+
return {
|
|
135
|
+
mrzText,
|
|
136
|
+
parsedResult
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// If not valid, try OCR corrections
|
|
141
|
+
const corrections = applyOCRCorrections(mrzText);
|
|
142
|
+
for (const correctedMRZ of corrections) {
|
|
143
|
+
try {
|
|
144
|
+
const correctedResult = parse(correctedMRZ, {
|
|
145
|
+
autocorrect: true
|
|
146
|
+
});
|
|
147
|
+
if (isValidParse(correctedResult)) {
|
|
148
|
+
console.log('[MRZ] OCR correction applied successfully');
|
|
149
|
+
return {
|
|
150
|
+
mrzText: correctedMRZ,
|
|
151
|
+
parsedResult: correctedResult
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
} catch (e) {
|
|
155
|
+
// Continue trying other corrections
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// Return original result even if not fully valid (for partial matches)
|
|
63
160
|
if (parsedResult.fields.firstName && parsedResult.fields.lastName && parsedResult.fields.birthDate && parsedResult.fields.expirationDate && parsedResult.fields.documentNumber && parsedResult.fields.issuingState) {
|
|
64
161
|
return {
|
|
65
162
|
mrzText,
|
|
@@ -91,6 +91,11 @@ export default {
|
|
|
91
91
|
'eidScannerScreen.readingDocument': 'Please hold steady and wait until the reading process is complete.',
|
|
92
92
|
'eidScannerScreen.checkYourInformation': "Please review your information. To continue, press 'Approve and Continue'.",
|
|
93
93
|
'eidScannerScreen.approveAndContinue': 'Approve and Continue',
|
|
94
|
+
'eidScannerScreen.connecting': 'Connecting to chip...',
|
|
95
|
+
'eidScannerScreen.readingMRZ': 'Reading document information...',
|
|
96
|
+
'eidScannerScreen.readingFaceImage': 'Reading photo...',
|
|
97
|
+
'eidScannerScreen.completing': 'Completing scan...',
|
|
98
|
+
'eidScannerScreen.progress': 'Progress',
|
|
94
99
|
'identityDocumentCamera.guideHeader': 'Is Your Identity Document Ready?',
|
|
95
100
|
'identityDocumentCamera.guideText': 'Before you begin, please note the following:',
|
|
96
101
|
'identityDocumentCamera.guidePoint1': 'The document must be clear and legible',
|
|
@@ -102,6 +107,31 @@ export default {
|
|
|
102
107
|
'identityDocumentCamera.alignIDFrontSide': 'Align the front side of your identity document with the camera.',
|
|
103
108
|
'identityDocumentCamera.alignIDBackSide': 'Align the back side of your identity document with the camera.',
|
|
104
109
|
'identityDocumentCamera.scanCompleted': 'Scan completed successfully.',
|
|
110
|
+
'identityDocumentCamera.frontSideScanned': 'Front side scanned!',
|
|
111
|
+
'identityDocumentCamera.passportScanned': 'Passport scanned!',
|
|
112
|
+
'identityDocumentCamera.backSideScanned': 'Back side scanned!',
|
|
113
|
+
'identityDocumentCamera.hologramVerified': 'Scanned!',
|
|
114
|
+
'identityDocumentCamera.searchingDocument': 'Position your document inside the frame',
|
|
115
|
+
'identityDocumentCamera.faceDetected': 'Photo detected! Hold steady...',
|
|
116
|
+
'identityDocumentCamera.readingDocument': 'Reading document...',
|
|
117
|
+
'identityDocumentCamera.processing': 'Processing...',
|
|
118
|
+
'identityDocumentCamera.stepProgress': 'Step {{current}} of {{total}}',
|
|
119
|
+
'identityDocumentCamera.frontSide': 'Front Side',
|
|
120
|
+
'identityDocumentCamera.backSide': 'Back Side',
|
|
121
|
+
'identityDocumentCamera.hologramCheck': 'Hologram Verification',
|
|
122
|
+
'identityDocumentCamera.keepSteady': 'Keep the document steady',
|
|
123
|
+
'identityDocumentCamera.avoidBlur': 'Hold steady or move document away to refocus',
|
|
124
|
+
'identityDocumentCamera.wrongSideFront': 'Wrong side! Please show the front side',
|
|
125
|
+
'identityDocumentCamera.wrongSideBack': 'Wrong side! Please flip to the back side',
|
|
126
|
+
'identityDocumentCamera.idCardDetected': 'ID card detected',
|
|
127
|
+
'identityDocumentCamera.idCardFrontDetected': 'ID card front detected! Hold steady...',
|
|
128
|
+
'identityDocumentCamera.passportDetected': 'Passport detected! Hold steady...',
|
|
129
|
+
'identityDocumentCamera.moveCloser': 'Move closer to the document',
|
|
130
|
+
'identityDocumentCamera.moveFarther': 'Move farther from the document',
|
|
131
|
+
'identityDocumentCamera.documentTooSmall': 'Document too small - move closer',
|
|
132
|
+
'identityDocumentCamera.documentTooLarge': 'Document too large - move back',
|
|
133
|
+
'identityDocumentCamera.holdSteady': 'Hold steady',
|
|
134
|
+
'identityDocumentCamera.centerDocument': 'Center the document in frame',
|
|
105
135
|
'navigationManager.skipStepWarning': 'It is recommended to complete this step. Are you sure you want to skip it?',
|
|
106
136
|
'navigationManager.skipStepLabel': 'Skip This Step'
|
|
107
137
|
};
|
|
@@ -91,6 +91,11 @@ export default {
|
|
|
91
91
|
'eidScannerScreen.readingDocument': 'Lütfen sabit tutun ve okuma işlemi tamamlanana kadar bekleyin.',
|
|
92
92
|
'eidScannerScreen.checkYourInformation': "Lütfen bilgilerinizi kontrol edin. Devam etmek için 'Onayla ve Devam Et' düğmesine basın.",
|
|
93
93
|
'eidScannerScreen.approveAndContinue': 'Onayla ve Devam Et',
|
|
94
|
+
'eidScannerScreen.connecting': 'Çipe bağlanılıyor...',
|
|
95
|
+
'eidScannerScreen.readingMRZ': 'Belge bilgileri okunuyor...',
|
|
96
|
+
'eidScannerScreen.readingFaceImage': 'Fotoğraf okunuyor...',
|
|
97
|
+
'eidScannerScreen.completing': 'Tarama tamamlanıyor...',
|
|
98
|
+
'eidScannerScreen.progress': 'İlerleme',
|
|
94
99
|
'identityDocumentCamera.guideHeader': 'Kimlik Belgeniz Hazır Mı?',
|
|
95
100
|
'identityDocumentCamera.guideText': 'Başlamadan önce lütfen aşağıdaki hususlara dikkat edin:',
|
|
96
101
|
'identityDocumentCamera.guidePoint1': 'Belge açık ve okunaklı olmalı',
|
|
@@ -102,6 +107,31 @@ export default {
|
|
|
102
107
|
'identityDocumentCamera.alignIDFrontSide': 'Kimlik belgenizin ön yüzünü kameraya hizalayın.',
|
|
103
108
|
'identityDocumentCamera.alignIDBackSide': 'Kimlik belgenizin arka yüzünü kameraya hizalayın.',
|
|
104
109
|
'identityDocumentCamera.scanCompleted': 'Tarama başarıyla tamamlandı.',
|
|
110
|
+
'identityDocumentCamera.frontSideScanned': 'Ön yüz tarandı!',
|
|
111
|
+
'identityDocumentCamera.passportScanned': 'Pasaport tarandı!',
|
|
112
|
+
'identityDocumentCamera.backSideScanned': 'Arka yüz tarandı!',
|
|
113
|
+
'identityDocumentCamera.hologramVerified': 'Tarandı!',
|
|
114
|
+
'identityDocumentCamera.searchingDocument': 'Belgenizi çerçeve içine konumlandırın',
|
|
115
|
+
'identityDocumentCamera.faceDetected': 'Fotoğraf algılandı! Sabit tutun...',
|
|
116
|
+
'identityDocumentCamera.readingDocument': 'Belge okunuyor...',
|
|
117
|
+
'identityDocumentCamera.processing': 'İşleniyor...',
|
|
118
|
+
'identityDocumentCamera.stepProgress': 'Adım {{current}} / {{total}}',
|
|
119
|
+
'identityDocumentCamera.frontSide': 'Ön Yüz',
|
|
120
|
+
'identityDocumentCamera.backSide': 'Arka Yüz',
|
|
121
|
+
'identityDocumentCamera.hologramCheck': 'Hologram Doğrulama',
|
|
122
|
+
'identityDocumentCamera.keepSteady': 'Belgeyi sabit tutun',
|
|
123
|
+
'identityDocumentCamera.avoidBlur': 'Sabit tutun veya yeniden odaklamak için belgeyi uzaklaştırın',
|
|
124
|
+
'identityDocumentCamera.wrongSideFront': 'Yanlış yüz! Lütfen ön yüzü gösterin',
|
|
125
|
+
'identityDocumentCamera.wrongSideBack': 'Yanlış yüz! Lütfen arka yüze çevirin',
|
|
126
|
+
'identityDocumentCamera.idCardDetected': 'Kimlik kartı algılandı',
|
|
127
|
+
'identityDocumentCamera.idCardFrontDetected': 'Kimlik kartı ön yüzü algılandı! Sabit tutun...',
|
|
128
|
+
'identityDocumentCamera.passportDetected': 'Pasaport algılandı! Sabit tutun...',
|
|
129
|
+
'identityDocumentCamera.moveCloser': 'Belgeye daha yakın gelin',
|
|
130
|
+
'identityDocumentCamera.moveFarther': 'Belgeden daha uzaklaşın',
|
|
131
|
+
'identityDocumentCamera.documentTooSmall': 'Belge çok küçük - yaklaşın',
|
|
132
|
+
'identityDocumentCamera.documentTooLarge': 'Belge çok büyük - uzaklaşın',
|
|
133
|
+
'identityDocumentCamera.holdSteady': 'Sabit tutun',
|
|
134
|
+
'identityDocumentCamera.centerDocument': 'Belgeyi çerçevede ortalayın',
|
|
105
135
|
'navigationManager.skipStepWarning': 'Bu adımı tamamlamanız önerilir. Adımı atlamak istediğinize emin misiniz?',
|
|
106
136
|
'navigationManager.skipStepLabel': 'Bu Adımı Atla'
|
|
107
137
|
};
|