scandoc-ai-components 0.0.23 → 0.0.25
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 +30 -42
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11170,6 +11170,7 @@ class ExtractorVideo {
|
|
|
11170
11170
|
static VALIDATION_BATCH_SIZE = 1;
|
|
11171
11171
|
static VALIDATION_IMG_WIDTH = 384;
|
|
11172
11172
|
static VALIDATION_IMG_HEIGHT = 384;
|
|
11173
|
+
static MAX_SCAN_DURATION_MS = 10000;
|
|
11173
11174
|
static VIDEO_SETTINGS = Object.freeze({
|
|
11174
11175
|
width: {
|
|
11175
11176
|
ideal: 1920
|
|
@@ -11185,25 +11186,21 @@ class ExtractorVideo {
|
|
|
11185
11186
|
this.onExtractedResults = onExtractedResults;
|
|
11186
11187
|
this.pastBlurValues = [];
|
|
11187
11188
|
this.isRunning = false;
|
|
11188
|
-
this.
|
|
11189
|
-
this.
|
|
11190
|
-
this.failedValidations = 0;
|
|
11191
|
-
this.MAX_FAILED_VALIDATIONS = 5;
|
|
11192
|
-
this.failedExtractionAttempts = 0;
|
|
11193
|
-
this.MAX_EXTRACTION_ATTEMPTS = 3;
|
|
11189
|
+
this.scanStartTime = null;
|
|
11190
|
+
this.timeoutTimer = null;
|
|
11194
11191
|
}
|
|
11195
11192
|
async analyzeVideoStream() {
|
|
11196
11193
|
if (!this.isRunning) {
|
|
11197
11194
|
return;
|
|
11198
11195
|
}
|
|
11199
11196
|
//
|
|
11200
|
-
const
|
|
11201
|
-
if (
|
|
11197
|
+
const now = Date.now();
|
|
11198
|
+
if (this.scanStartTime && now - this.scanStartTime > ExtractorVideo.MAX_SCAN_DURATION_MS) {
|
|
11202
11199
|
this.stopVideo();
|
|
11203
11200
|
this.onExtractedResults({
|
|
11204
11201
|
success: false,
|
|
11205
11202
|
code: "TIMEOUT",
|
|
11206
|
-
|
|
11203
|
+
info: "Document not detected within time limit."
|
|
11207
11204
|
});
|
|
11208
11205
|
return;
|
|
11209
11206
|
}
|
|
@@ -11222,21 +11219,6 @@ class ExtractorVideo {
|
|
|
11222
11219
|
const images = [...this.candidateImages];
|
|
11223
11220
|
if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
|
|
11224
11221
|
const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_2__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
|
|
11225
|
-
if (!isValidationOk) {
|
|
11226
|
-
this.failedValidations++;
|
|
11227
|
-
if (this.failedValidations >= this.MAX_FAILED_VALIDATIONS) {
|
|
11228
|
-
this.stopVideo();
|
|
11229
|
-
this.onExtractedResults({
|
|
11230
|
-
success: false,
|
|
11231
|
-
code: "VALIDATION_FAILED",
|
|
11232
|
-
message: "Document validation failed repeatedly."
|
|
11233
|
-
});
|
|
11234
|
-
return;
|
|
11235
|
-
}
|
|
11236
|
-
this.candidateImages = [];
|
|
11237
|
-
return;
|
|
11238
|
-
}
|
|
11239
|
-
this.failedValidations = 0;
|
|
11240
11222
|
if (isValidationOk) {
|
|
11241
11223
|
this.showMessage(response["Info"]);
|
|
11242
11224
|
//
|
|
@@ -11280,6 +11262,13 @@ class ExtractorVideo {
|
|
|
11280
11262
|
this.onExtraction(isExtractionOk, extractionData);
|
|
11281
11263
|
return;
|
|
11282
11264
|
}
|
|
11265
|
+
} else {
|
|
11266
|
+
this.candidateImages = [];
|
|
11267
|
+
this.onExtractedResults({
|
|
11268
|
+
success: false,
|
|
11269
|
+
code: "VALIDATION_FAILED",
|
|
11270
|
+
info: "Validation of document image failed."
|
|
11271
|
+
});
|
|
11283
11272
|
}
|
|
11284
11273
|
this.candidateImages = [];
|
|
11285
11274
|
}
|
|
@@ -11293,21 +11282,21 @@ class ExtractorVideo {
|
|
|
11293
11282
|
this.extractionImages = {};
|
|
11294
11283
|
if (isExtractionOk) {
|
|
11295
11284
|
this.showMessage("Success - data extracted", "success");
|
|
11296
|
-
const shouldStop = this.onExtractedResults(
|
|
11285
|
+
const shouldStop = this.onExtractedResults({
|
|
11286
|
+
success: true,
|
|
11287
|
+
code: "EXTRACTION_OK",
|
|
11288
|
+
info: "Document extracted successfully.",
|
|
11289
|
+
data: extractionData
|
|
11290
|
+
});
|
|
11297
11291
|
if (shouldStop === true) {
|
|
11298
11292
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11299
11293
|
}
|
|
11300
11294
|
} else {
|
|
11301
|
-
this.
|
|
11302
|
-
|
|
11303
|
-
|
|
11304
|
-
|
|
11305
|
-
|
|
11306
|
-
code: "EXTRACTION_FAILED",
|
|
11307
|
-
message: "Document extraction failed."
|
|
11308
|
-
});
|
|
11309
|
-
return;
|
|
11310
|
-
}
|
|
11295
|
+
this.onExtractedResults({
|
|
11296
|
+
success: false,
|
|
11297
|
+
code: "EXTRACTION_FAILED",
|
|
11298
|
+
info: "Document validation passed but extraction failed."
|
|
11299
|
+
});
|
|
11311
11300
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11312
11301
|
}
|
|
11313
11302
|
}
|
|
@@ -11316,10 +11305,10 @@ class ExtractorVideo {
|
|
|
11316
11305
|
if (videoElem !== undefined) {
|
|
11317
11306
|
this.video = videoElem;
|
|
11318
11307
|
this.isRunning = true;
|
|
11308
|
+
this.scanStartTime = Date.now();
|
|
11319
11309
|
navigator.mediaDevices.enumerateDevices().then(devices => {
|
|
11320
11310
|
const environmentCameras = devices.filter(device => device.kind === "videoinput" && device.label.toLowerCase().includes("back"));
|
|
11321
11311
|
checkAutofocusSupport(environmentCameras).then(cameras => {
|
|
11322
|
-
console.log("Got autofocus camera:", cameras);
|
|
11323
11312
|
let deviceId = undefined;
|
|
11324
11313
|
let deviceFound = false;
|
|
11325
11314
|
if (cameras.length > 0) {
|
|
@@ -11332,7 +11321,6 @@ class ExtractorVideo {
|
|
|
11332
11321
|
if (deviceFound) {
|
|
11333
11322
|
userMediaConstraints.deviceId = deviceId;
|
|
11334
11323
|
}
|
|
11335
|
-
//
|
|
11336
11324
|
navigator.mediaDevices.getUserMedia({
|
|
11337
11325
|
video: userMediaConstraints
|
|
11338
11326
|
}).then(stream => {
|
|
@@ -11340,14 +11328,14 @@ class ExtractorVideo {
|
|
|
11340
11328
|
this.video.play().catch(e => {
|
|
11341
11329
|
console.warn(`Error on video play: ${e}`);
|
|
11342
11330
|
});
|
|
11343
|
-
//
|
|
11331
|
+
this.scanStartTime = Date.now(); // Reset timer
|
|
11344
11332
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|
|
11345
11333
|
}).catch(error => {
|
|
11346
11334
|
console.log("Error accessing the camera: " + error);
|
|
11347
11335
|
this.onExtractedResults({
|
|
11348
11336
|
success: false,
|
|
11349
|
-
code: "
|
|
11350
|
-
|
|
11337
|
+
code: "CAMERA_ACCESS_DENIED",
|
|
11338
|
+
info: "Could not access the camera. Permission denied or not found."
|
|
11351
11339
|
});
|
|
11352
11340
|
});
|
|
11353
11341
|
});
|
|
@@ -11355,8 +11343,8 @@ class ExtractorVideo {
|
|
|
11355
11343
|
console.log("Error accessing the camera: " + error);
|
|
11356
11344
|
this.onExtractedResults({
|
|
11357
11345
|
success: false,
|
|
11358
|
-
code: "
|
|
11359
|
-
|
|
11346
|
+
code: "CAMERA_ENUMERATION_FAILED",
|
|
11347
|
+
info: "Could not enumerate video input devices."
|
|
11360
11348
|
});
|
|
11361
11349
|
});
|
|
11362
11350
|
this.showMessage("Starting scanning");
|