@jaak.ai/stamps 2.0.0-dev.47 → 2.0.0-dev.48
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/cjs/jaak-stamps.cjs.entry.js +34 -16
- package/dist/cjs/jaak-stamps.cjs.entry.js.map +1 -1
- package/dist/cjs/jaak-stamps.entry.cjs.js.map +1 -1
- package/dist/collection/services/DetectionService.js +34 -16
- package/dist/collection/services/DetectionService.js.map +1 -1
- package/dist/components/jaak-stamps.js +34 -16
- package/dist/components/jaak-stamps.js.map +1 -1
- package/dist/esm/jaak-stamps.entry.js +34 -16
- package/dist/esm/jaak-stamps.entry.js.map +1 -1
- package/dist/jaak-stamps-webcomponent/jaak-stamps-webcomponent.esm.js +1 -1
- package/dist/jaak-stamps-webcomponent/jaak-stamps.entry.esm.js.map +1 -1
- package/dist/jaak-stamps-webcomponent/p-6514d12b.entry.js +2 -0
- package/dist/jaak-stamps-webcomponent/p-6514d12b.entry.js.map +1 -0
- package/package.json +1 -1
- package/dist/jaak-stamps-webcomponent/p-e9c243e9.entry.js +0 -2
- package/dist/jaak-stamps-webcomponent/p-e9c243e9.entry.js.map +0 -1
|
@@ -728,7 +728,7 @@ class DetectionService {
|
|
|
728
728
|
modelLoaded = false;
|
|
729
729
|
deviceStrategy;
|
|
730
730
|
MODEL_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/ddmyp-v2.onnx";
|
|
731
|
-
MOBILENET_MODEL_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/
|
|
731
|
+
MOBILENET_MODEL_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/squeezenet.onnx";
|
|
732
732
|
MOBILENET_CLASSES_PATH = "https://storage.googleapis.com/jaak-static/web/component/stamps/cdmmp-v1.json";
|
|
733
733
|
INPUT_SIZE = 320;
|
|
734
734
|
CONFIDENCE_THRESHOLD = 0.6;
|
|
@@ -790,15 +790,27 @@ class DetectionService {
|
|
|
790
790
|
}
|
|
791
791
|
try {
|
|
792
792
|
this.logger.state('CARGANDO_MODELO_MOBILENET', { path: this.MOBILENET_MODEL_PATH });
|
|
793
|
-
//
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
793
|
+
// Try to load class map (optional - SqueezeNet may not need it for basic classification)
|
|
794
|
+
try {
|
|
795
|
+
const classResponse = await fetch(this.MOBILENET_CLASSES_PATH);
|
|
796
|
+
if (classResponse.ok) {
|
|
797
|
+
this.mobileNetClassMap = await classResponse.json();
|
|
798
|
+
this.logger.state('CLASES_MOBILENET_CARGADAS', {
|
|
799
|
+
classCount: Object.keys(this.mobileNetClassMap).length
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
catch (error) {
|
|
804
|
+
this.logger.warn('No se pudo cargar el mapa de clases de MobileNet, usando clasificación básica');
|
|
805
|
+
// Create a basic class map for document types
|
|
806
|
+
this.mobileNetClassMap = {
|
|
807
|
+
"0": "document",
|
|
808
|
+
"1": "id_card",
|
|
809
|
+
"2": "passport",
|
|
810
|
+
"3": "license",
|
|
811
|
+
"4": "other"
|
|
812
|
+
};
|
|
797
813
|
}
|
|
798
|
-
this.mobileNetClassMap = await classResponse.json();
|
|
799
|
-
this.logger.state('CLASES_MOBILENET_CARGADAS', {
|
|
800
|
-
classCount: Object.keys(this.mobileNetClassMap).length
|
|
801
|
-
});
|
|
802
814
|
// Load model
|
|
803
815
|
const sessionOptions = this.deviceStrategy.getSessionOptions(this.debug);
|
|
804
816
|
try {
|
|
@@ -887,7 +899,7 @@ class DetectionService {
|
|
|
887
899
|
try {
|
|
888
900
|
this.logger.state('CLASIFICANDO_DOCUMENTO', { timestamp: Date.now() });
|
|
889
901
|
const inputTensor = this.preprocessMobileNet(canvas);
|
|
890
|
-
const feeds = {
|
|
902
|
+
const feeds = { [this.mobileNetSession.inputNames[0]]: inputTensor };
|
|
891
903
|
const results = await this.mobileNetSession.run(feeds);
|
|
892
904
|
const output = results[Object.keys(results)[0]].data;
|
|
893
905
|
const maxIdx = output.reduce((bestIdx, val, idx, arr) => val > arr[bestIdx] ? idx : bestIdx, 0);
|
|
@@ -897,7 +909,8 @@ class DetectionService {
|
|
|
897
909
|
class: className,
|
|
898
910
|
confidence: confidence.toFixed(3),
|
|
899
911
|
classIndex: maxIdx,
|
|
900
|
-
timestamp: Date.now()
|
|
912
|
+
timestamp: Date.now(),
|
|
913
|
+
results
|
|
901
914
|
});
|
|
902
915
|
return {
|
|
903
916
|
class: className,
|
|
@@ -936,7 +949,7 @@ class DetectionService {
|
|
|
936
949
|
displayedVideoHeight = INPUT_SIZE / videoAspectRatio;
|
|
937
950
|
}
|
|
938
951
|
else {
|
|
939
|
-
// Video is taller - pillarboxed in display
|
|
952
|
+
// Video is taller - pillarboxed in display
|
|
940
953
|
displayedVideoHeight = INPUT_SIZE;
|
|
941
954
|
displayedVideoWidth = INPUT_SIZE * videoAspectRatio;
|
|
942
955
|
}
|
|
@@ -987,7 +1000,7 @@ class DetectionService {
|
|
|
987
1000
|
const leftAligned = Math.abs(docLeft - maskLeft) <= tolerance;
|
|
988
1001
|
return {
|
|
989
1002
|
top: topAligned && leftAligned, // Esquina superior izquierda: borde top Y left alineados
|
|
990
|
-
right: topAligned && rightAligned, // Esquina superior derecha: borde top Y right alineados
|
|
1003
|
+
right: topAligned && rightAligned, // Esquina superior derecha: borde top Y right alineados
|
|
991
1004
|
bottom: bottomAligned && leftAligned, // Esquina inferior izquierda: borde bottom Y left alineados
|
|
992
1005
|
left: bottomAligned && rightAligned // Esquina inferior derecha: borde bottom Y right alineados
|
|
993
1006
|
};
|
|
@@ -1072,15 +1085,20 @@ class DetectionService {
|
|
|
1072
1085
|
tempCanvas.width = 224;
|
|
1073
1086
|
tempCanvas.height = 224;
|
|
1074
1087
|
const tempCtx = tempCanvas.getContext('2d');
|
|
1088
|
+
// Resize image to 224x224 for SqueezeNet (using MobileNet interface)
|
|
1075
1089
|
tempCtx.drawImage(canvas, 0, 0, 224, 224);
|
|
1076
1090
|
const imageData = tempCtx.getImageData(0, 0, 224, 224);
|
|
1077
1091
|
const data = imageData.data;
|
|
1078
1092
|
const hw = 224 * 224;
|
|
1079
1093
|
const arr = new Float32Array(3 * hw);
|
|
1094
|
+
// SqueezeNet preprocessing: normalize to [0,1] range and arrange in CHW format
|
|
1080
1095
|
for (let i = 0; i < hw; i++) {
|
|
1081
|
-
|
|
1082
|
-
arr[
|
|
1083
|
-
|
|
1096
|
+
// Red channel
|
|
1097
|
+
arr[i] = data[i * 4 + 0] / 255.0;
|
|
1098
|
+
// Green channel
|
|
1099
|
+
arr[hw + i] = data[i * 4 + 1] / 255.0;
|
|
1100
|
+
// Blue channel
|
|
1101
|
+
arr[2 * hw + i] = data[i * 4 + 2] / 255.0;
|
|
1084
1102
|
}
|
|
1085
1103
|
return new window.ort.Tensor('float32', arr, [1, 3, 224, 224]);
|
|
1086
1104
|
}
|