@ekyc_qoobiss/qbs-ect-cmp 4.7.23 → 4.7.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.
@@ -592,87 +592,93 @@ const IdAutoCapture = class {
592
592
  // Method for continuous video frame processing with OpenCV
593
593
  this.processVideoFrame = () => {
594
594
  if (this.videoElement && this.processingCanvasElement && this.opencvReady && this.isDetecting) {
595
- const video = this.videoElement;
596
- const processingCanvas = this.processingCanvasElement;
597
- const context = processingCanvas.getContext('2d');
598
- processingCanvas.width = video.videoWidth;
599
- processingCanvas.height = video.videoHeight;
600
- context.drawImage(video, 0, 0, processingCanvas.width, processingCanvas.height);
601
- const imageData = context.getImageData(0, 0, processingCanvas.width, processingCanvas.height);
602
- // --- OpenCV.js processing starts here ---
603
- let src = new cv.Mat(processingCanvas.height, processingCanvas.width, cv.CV_8UC4);
604
- src.data.set(imageData.data);
605
- let gray = new cv.Mat();
606
- let blurred = new cv.Mat();
607
- let edges = new cv.Mat();
608
- let contours = new cv.MatVector();
609
- let hierarchy = new cv.Mat();
610
595
  try {
611
- cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0);
612
- cv.GaussianBlur(gray, blurred, new cv.Size(5, 5), 0, 0, cv.BORDER_DEFAULT);
613
- cv.Canny(blurred, edges, 75, 200, 3, false);
614
- cv.findContours(edges, contours, hierarchy, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE);
615
- let idDetected = false;
616
- let maxArea = 0;
617
- //let bestRect = null;
618
- for (let i = 0; i < contours.size(); ++i) {
619
- let contour = contours.get(i);
620
- let area = cv.contourArea(contour);
621
- if (area > 1000 && area > maxArea) {
622
- let peri = cv.arcLength(contour, true);
623
- let approx = new cv.Mat();
624
- cv.approxPolyDP(contour, approx, 0.02 * peri, true);
625
- if (approx.rows === 4) {
626
- let rect = cv.boundingRect(approx);
627
- const aspectRatio = rect.width / rect.height;
628
- if (aspectRatio > 1.4 && aspectRatio < 1.8) {
629
- if (rect.width > video.videoWidth * 0.3 && rect.height > video.videoHeight * 0.3) {
630
- idDetected = true;
631
- maxArea = area;
632
- //bestRect = rect;
596
+ console.log('Processing frame. cv.Mat is a constructor:', typeof cv.Mat === 'function');
597
+ const video = this.videoElement;
598
+ const processingCanvas = this.processingCanvasElement;
599
+ const context = processingCanvas.getContext('2d');
600
+ processingCanvas.width = video.videoWidth;
601
+ processingCanvas.height = video.videoHeight;
602
+ context.drawImage(video, 0, 0, processingCanvas.width, processingCanvas.height);
603
+ const imageData = context.getImageData(0, 0, processingCanvas.width, processingCanvas.height);
604
+ // --- OpenCV.js processing starts here ---
605
+ let src = new cv.Mat(processingCanvas.height, processingCanvas.width, cv.CV_8UC4);
606
+ src.data.set(imageData.data);
607
+ let gray = new cv.Mat();
608
+ let blurred = new cv.Mat();
609
+ let edges = new cv.Mat();
610
+ let contours = new cv.MatVector();
611
+ let hierarchy = new cv.Mat();
612
+ try {
613
+ cv.cvtColor(src, gray, cv.COLOR_RGBA2GRAY, 0);
614
+ cv.GaussianBlur(gray, blurred, new cv.Size(5, 5), 0, 0, cv.BORDER_DEFAULT);
615
+ cv.Canny(blurred, edges, 75, 200, 3, false);
616
+ cv.findContours(edges, contours, hierarchy, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE);
617
+ let idDetected = false;
618
+ let maxArea = 0;
619
+ //let bestRect = null;
620
+ for (let i = 0; i < contours.size(); ++i) {
621
+ let contour = contours.get(i);
622
+ let area = cv.contourArea(contour);
623
+ if (area > 1000 && area > maxArea) {
624
+ let peri = cv.arcLength(contour, true);
625
+ let approx = new cv.Mat();
626
+ cv.approxPolyDP(contour, approx, 0.02 * peri, true);
627
+ if (approx.rows === 4) {
628
+ let rect = cv.boundingRect(approx);
629
+ const aspectRatio = rect.width / rect.height;
630
+ if (aspectRatio > 1.4 && aspectRatio < 1.8) {
631
+ if (rect.width > video.videoWidth * 0.3 && rect.height > video.videoHeight * 0.3) {
632
+ idDetected = true;
633
+ maxArea = area;
634
+ //bestRect = rect;
635
+ }
633
636
  }
634
637
  }
638
+ approx.delete();
639
+ }
640
+ contour.delete();
641
+ }
642
+ if (idDetected) {
643
+ console.log('ID document detected! Starting countdown...');
644
+ this.countdown = 3;
645
+ if (this.animationFrameId !== null) {
646
+ cancelAnimationFrame(this.animationFrameId); // Stop continuous frame processing
647
+ this.animationFrameId = null;
635
648
  }
636
- approx.delete();
649
+ const timer = setInterval(() => {
650
+ this.countdown--;
651
+ if (this.countdown <= 0) {
652
+ clearInterval(timer);
653
+ this.capture();
654
+ this.stopRecording();
655
+ this.isDetecting = false;
656
+ console.log('Picture taken. You can now stop recording.');
657
+ this.countdown = 0; // Ensure countdown is 0
658
+ }
659
+ }, 1000);
637
660
  }
638
- contour.delete();
639
661
  }
640
- if (idDetected) {
641
- console.log('ID document detected! Starting countdown...');
642
- this.countdown = 3;
662
+ catch (error) {
663
+ console.error('OpenCV processing error:', error);
664
+ this.isDetecting = false; // Stop detection on error
643
665
  if (this.animationFrameId !== null) {
644
- cancelAnimationFrame(this.animationFrameId); // Stop continuous frame processing
666
+ cancelAnimationFrame(this.animationFrameId);
645
667
  this.animationFrameId = null;
646
668
  }
647
- const timer = setInterval(() => {
648
- this.countdown--;
649
- if (this.countdown <= 0) {
650
- clearInterval(timer);
651
- this.capture();
652
- this.stopRecording();
653
- this.isDetecting = false;
654
- console.log('Picture taken. You can now stop recording.');
655
- this.countdown = 0; // Ensure countdown is 0
656
- }
657
- }, 1000);
658
669
  }
659
- }
660
- catch (error) {
661
- console.error('OpenCV processing error:', error);
662
- this.isDetecting = false; // Stop detection on error
663
- if (this.animationFrameId !== null) {
664
- cancelAnimationFrame(this.animationFrameId);
665
- this.animationFrameId = null;
670
+ finally {
671
+ // Crucial: Release memory allocated by OpenCV Mat objects
672
+ src.delete();
673
+ gray.delete();
674
+ blurred.delete();
675
+ edges.delete();
676
+ contours.delete();
677
+ hierarchy.delete();
666
678
  }
667
679
  }
668
- finally {
669
- // Crucial: Release memory allocated by OpenCV Mat objects
670
- src.delete();
671
- gray.delete();
672
- blurred.delete();
673
- edges.delete();
674
- contours.delete();
675
- hierarchy.delete();
680
+ catch (error) {
681
+ console.error('Error processing video frame with OpenCV:', error);
676
682
  }
677
683
  // --- OpenCV.js processing ends here ---
678
684
  }
@@ -734,10 +740,6 @@ const IdAutoCapture = class {
734
740
  this.loadOpenCVScript();
735
741
  // Listen for the custom event dispatched by global.ts (ensures global.ts sets up window.Module)
736
742
  document.addEventListener('opencv:ready', this.handleOpencvReady);
737
- // Initial check in case opencv.js loads very fast and event was already dispatched
738
- if (typeof cv !== 'undefined' && cv.Mat) {
739
- this.handleOpencvReady();
740
- }
741
743
  }
742
744
  disconnectedCallback() {
743
745
  if (this.mediaStream) {
@@ -758,7 +760,7 @@ const IdAutoCapture = class {
758
760
  }
759
761
  }
760
762
  loadOpenCVScript() {
761
- if (!this.opencvScriptElement) {
763
+ if (!document.querySelector('script[src="https://docs.opencv.org/4.x/opencv.js"]')) {
762
764
  // Only load if not already loaded
763
765
  this.opencvScriptElement = document.createElement('script');
764
766
  this.opencvScriptElement.type = 'text/javascript';
@@ -767,6 +769,9 @@ const IdAutoCapture = class {
767
769
  document.body.appendChild(this.opencvScriptElement); // Append to body or head
768
770
  console.log('Dynamically loaded opencv.js');
769
771
  }
772
+ else {
773
+ console.log('OpenCV.js script already present in the DOM.');
774
+ }
770
775
  }
771
776
  // Method to get user media (camera stream)
772
777
  async getMedia() {
@@ -791,7 +796,7 @@ const IdAutoCapture = class {
791
796
  if (TranslationUtils.state.device.isDesktop) {
792
797
  cameraVideoClass = 'cameraVideoSelfieDesk';
793
798
  }
794
- return (index.h("div", { key: '32fa99f679fbbc0009608aeb2eeb26645dbadb59', class: "container flex center" }, index.h("div", { key: '08ee0848724b359253d27120fe5e2751372cab1e', class: "px-2 w-100" }, index.h("h1", { key: '570154c491f44b72f5a6794f17b1a19c964a55e5', class: this.titleStyle, innerHTML: this.titleMesage }), index.h("div", { key: '2a626737524f5748e4d6faeb109f3dc59fe3388b', hidden: this.verified }, index.h("div", { key: 'f38962922b06f902790d9d549c3d1c507cafb8b8', class: "w-100 h-100 rounded" }, index.h("div", { key: '7c69f659183dfdfab7ea759c1a5a574af19df679', class: "camera rounded" }, index.h("video", { key: '7f378deee95b9821715add1f9b66e9299b6e4380', id: "video", loop: true, autoplay: true, playsinline: true, muted: true, class: cameraVideoClass, ref: el => (this.videoElement = el) }), index.h("canvas", { key: '8150fbc30e908e011f415b73a0e3f2d8711f2d20', id: "output", ref: el => (this.canvasElement = el), style: { display: 'none' } }), index.h("canvas", { key: '54887d1f9266d32f653760ff6e70971e2d525c0a', id: "processingCanvasElement", ref: el => (this.processingCanvasElement = el), style: { display: 'none' } }), index.h("div", { key: 'cf656641dcb1cf1bf845c28a97630c72f7da8fe6', class: "id-guide-rectangle" }), this.isCapturing && index.h("div", { key: 'eabb935e014eb3966940a27a5aa100477249dbba', class: "capture-flash-overlay" }), this.countdown > 0 && (index.h("div", { key: 'e8a05e21e03673637e0194b3d967ed0044891a01', class: "absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center" }, index.h("span", { key: 'f6996d51686b935aa4aaa6f2abe4062d5782c116', class: "text-white text-9xl font-bold animate-bounce" }, this.countdown)))))), index.h("div", { key: 'd4fc6a0ff5951767a43f9166fcf47f98b4d209a7', class: "footer text-center" }, index.h("img", { key: 'a84cc0c65a6684807abf314d9839babe16768494', src: Cameras.logoOntraceSvg })))));
799
+ return (index.h("div", { key: 'deb2d35a50823fa5c222c6049a4119a371194870', class: "container flex center" }, index.h("div", { key: '449a0fef911f14d3611a1d7e83ed1bfc02c0553f', class: "px-2 w-100" }, index.h("h1", { key: '8d9f8b3684e58ba57f4ec0467efa0d9af62c5a98', class: this.titleStyle, innerHTML: this.titleMesage }), index.h("div", { key: '701aeecc148bdd00ef9cd38b165f0628adfe827c', hidden: this.verified }, index.h("div", { key: 'cbe89cf4ddc15c46b595929ecaf4fb8cc20136b5', class: "w-100 h-100 rounded" }, index.h("div", { key: '78f52a0a77c3dd8218115253bbcb79ee0a9a6d4b', class: "camera rounded" }, index.h("video", { key: '6ee76764205ce855fedd7b8c86be4394b2cad7bb', id: "video", loop: true, autoplay: true, playsinline: true, muted: true, class: cameraVideoClass, ref: el => (this.videoElement = el) }), index.h("canvas", { key: '5574b79a997d3ca06afa99faa61cb9bace755e91', id: "output", ref: el => (this.canvasElement = el), style: { display: 'none' } }), index.h("canvas", { key: 'e25df7ef70206d5544adade008cd612f1fee550a', id: "processingCanvasElement", ref: el => (this.processingCanvasElement = el), style: { display: 'none' } }), index.h("div", { key: '8ac6db08f2d1e44d04f2827f29e08787b853812e', class: "id-guide-rectangle" }), this.isCapturing && index.h("div", { key: '900ddcc0d2bf371d7ad4e593eaf0e9b60b6d2810', class: "capture-flash-overlay" }), this.countdown > 0 && (index.h("div", { key: 'd5f05c1b3dcbd02977462c6b9d816c2835698c2f', class: "absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center" }, index.h("span", { key: '7b85d36f1b609360c8214a29e220f6f80effffca', class: "text-white text-9xl font-bold animate-bounce" }, this.countdown)))))), index.h("div", { key: '9b653ebb92ce731ddb235d85db4a7fa99aaa4c64', class: "footer text-center" }, index.h("img", { key: 'f085d8f1698e66448cf749ec4cc45b496fbd55a1', src: Cameras.logoOntraceSvg })))));
795
800
  }
796
801
  get el() { return index.getElement(this); }
797
802
  };
@@ -856,7 +861,7 @@ const IdSelection = class {
856
861
  };
857
862
  IdSelection.style = idSelectionCss;
858
863
 
859
- const version$1 = "4.7.23";
864
+ const version$1 = "4.7.25";
860
865
  var packageJson = {
861
866
  version: version$1};
862
867