scandoc-ai-components 0.0.36 → 0.0.37
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 +11 -36
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -11188,10 +11188,7 @@ class ExtractorVideo {
|
|
|
11188
11188
|
this.pastBlurValues = [];
|
|
11189
11189
|
this.isRunning = false;
|
|
11190
11190
|
this.scanStartTime = null;
|
|
11191
|
-
this.
|
|
11192
|
-
this.validationStartTime = null;
|
|
11193
|
-
this.validationTimedOut = false;
|
|
11194
|
-
this.wasDocumentPreviouslyDetected = false;
|
|
11191
|
+
this.documentDetectionStartTime = null;
|
|
11195
11192
|
}
|
|
11196
11193
|
async analyzeVideoStream() {
|
|
11197
11194
|
if (!this.isRunning) {
|
|
@@ -11216,38 +11213,26 @@ class ExtractorVideo {
|
|
|
11216
11213
|
const fullImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, video.videoWidth, video.videoHeight, false);
|
|
11217
11214
|
const validationImage = (0,_utils__WEBPACK_IMPORTED_MODULE_4__.videoImgToBase64)(video, canvas, ExtractorVideo.VALIDATION_IMG_WIDTH, ExtractorVideo.VALIDATION_IMG_HEIGHT, true);
|
|
11218
11215
|
DOCUMENT_DETECTOR.isDocumentPresent(video).then(async isPresent => {
|
|
11219
|
-
const now_valid = Date.now();
|
|
11220
11216
|
if (isPresent) {
|
|
11221
|
-
if (!this.
|
|
11222
|
-
this.
|
|
11223
|
-
console.log("Document detected. Validation timer started:", this.validationStartTime);
|
|
11224
|
-
this.wasDocumentPreviouslyDetected = true;
|
|
11225
|
-
return;
|
|
11226
|
-
}
|
|
11227
|
-
this.wasDocumentPreviouslyDetected = true;
|
|
11228
|
-
console.log("Validation timer:", {
|
|
11229
|
-
start: this.validationStartTime,
|
|
11230
|
-
now: now_valid,
|
|
11231
|
-
elapsed: now_valid - this.validationStartTime,
|
|
11232
|
-
limit: cfgValues.VALIDATION_TIMEOUT_MS
|
|
11233
|
-
});
|
|
11234
|
-
if (this.validationStartTime && now_valid - this.validationStartTime > cfgValues.VALIDATION_TIMEOUT_MS) {
|
|
11235
|
-
this.stopVideo();
|
|
11236
|
-
this.onExtractedResults({
|
|
11237
|
-
success: false,
|
|
11238
|
-
code: "002",
|
|
11239
|
-
info: "Document was detected but validation did not succeed in time."
|
|
11240
|
-
});
|
|
11241
|
-
return;
|
|
11217
|
+
if (!this.documentDetectionStartTime) {
|
|
11218
|
+
this.documentDetectionStartTime = Date.now();
|
|
11242
11219
|
}
|
|
11243
11220
|
this.candidateImages.push({
|
|
11244
11221
|
fullImg: fullImage,
|
|
11245
11222
|
validationImg: validationImage
|
|
11246
11223
|
});
|
|
11247
11224
|
const images = [...this.candidateImages];
|
|
11225
|
+
const timeSinceFirstDetection = Date.now() - this.documentDetectionStartTime;
|
|
11226
|
+
if (timeSinceFirstDetection > cfgValues.VALIDATION_TIMEOUT_MS) {
|
|
11227
|
+
this.showMessage("Validation failed: timeout after 5 seconds.");
|
|
11228
|
+
this.documentDetectionStartTime = null;
|
|
11229
|
+
this.candidateImages = [];
|
|
11230
|
+
return;
|
|
11231
|
+
}
|
|
11248
11232
|
if (images.length >= ExtractorVideo.VALIDATION_BATCH_SIZE) {
|
|
11249
11233
|
const [isValidationOk, response] = await (0,_requests_validation__WEBPACK_IMPORTED_MODULE_3__["default"])(images.map(e => e["validationImg"]), this.pastBlurValues, {});
|
|
11250
11234
|
if (isValidationOk) {
|
|
11235
|
+
this.documentDetectionStartTime = null;
|
|
11251
11236
|
this.showMessage(response["Info"]);
|
|
11252
11237
|
//
|
|
11253
11238
|
if ("DetectedBlurValue" in response) {
|
|
@@ -11290,19 +11275,9 @@ class ExtractorVideo {
|
|
|
11290
11275
|
this.onExtraction(isExtractionOk, extractionData);
|
|
11291
11276
|
return;
|
|
11292
11277
|
}
|
|
11293
|
-
} else {
|
|
11294
|
-
this.wasDocumentPreviouslyDetected = false;
|
|
11295
|
-
this.candidateImages = [];
|
|
11296
11278
|
}
|
|
11297
|
-
this.validationStartTime = null;
|
|
11298
11279
|
this.candidateImages = [];
|
|
11299
11280
|
}
|
|
11300
|
-
} else {
|
|
11301
|
-
if (this.wasDocumentPreviouslyDetected) {
|
|
11302
|
-
console.log("Document lost. Resetting validation timer.");
|
|
11303
|
-
}
|
|
11304
|
-
this.wasDocumentPreviouslyDetected = false;
|
|
11305
|
-
this.validationStartTime = null;
|
|
11306
11281
|
}
|
|
11307
11282
|
}).finally(() => {
|
|
11308
11283
|
setTimeout(() => this.analyzeVideoStream(), ExtractorVideo.FREQUENCY_MS);
|