From 538b13aeecd976f39a48fd313b0d83a00d4ce875 Mon Sep 17 00:00:00 2001 From: Alexander Smorkalov Date: Wed, 14 Jun 2023 16:53:32 +0300 Subject: [PATCH] JS bindings for bar code detector. --- modules/js/generator/embindgen.py | 5 ----- modules/js/src/core_bindings.cpp | 3 +++ modules/js/test/test_objdetect.js | 21 +++++++++++++++++++++ platforms/js/opencv_js.config.py | 3 ++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/modules/js/generator/embindgen.py b/modules/js/generator/embindgen.py index d44e672823..8a16f92f5e 100644 --- a/modules/js/generator/embindgen.py +++ b/modules/js/generator/embindgen.py @@ -236,11 +236,6 @@ class ArgInfo(object): self.tp = "std::vector&" elif self.inputarg: self.tp = "const std::vector&" - if self.tp == "vector_string": - if self.outputarg: - self.tp = "std::vector&" - elif self.inputarg: - self.tp = "const std::vector&" self.tp = handle_vector(self.tp).strip() if self.const: self.tp = "const " + self.tp diff --git a/modules/js/src/core_bindings.cpp b/modules/js/src/core_bindings.cpp index 6771c42edb..60fe496ce3 100644 --- a/modules/js/src/core_bindings.cpp +++ b/modules/js/src/core_bindings.cpp @@ -101,6 +101,9 @@ using namespace cv::dnn; typedef TrackerMIL::Params TrackerMIL_Params; #endif +// HACK: JS generator ommits namespace for parameter types for some reason. Added typedef to handle std::string correctly +typedef std::string string; + namespace binding_utils { template diff --git a/modules/js/test/test_objdetect.js b/modules/js/test/test_objdetect.js index d4f6c5397b..e7190db337 100644 --- a/modules/js/test/test_objdetect.js +++ b/modules/js/test/test_objdetect.js @@ -221,6 +221,27 @@ QUnit.test('Aruco-based QR code detect', function (assert) { mat.delete(); } }); +QUnit.test('Bar code detect', function (assert) { + { + let detector = new cv.barcode_BarcodeDetector(); + let mat = cv.Mat.ones(800, 600, cv.CV_8U); + assert.ok(mat); + + let points = new cv.Mat(); + let codeFound = detector.detect(mat, points); + assert.equal(points.rows, 0) + assert.equal(points.cols, 0) + assert.equal(codeFound, false); + + codeContent = detector.detectAndDecode(mat); + assert.equal(typeof codeContent, 'string'); + assert.equal(codeContent, ''); + + detector.delete(); + points.delete(); + mat.delete(); + } +}); QUnit.test('Aruco detector', function (assert) { { let dictionary = cv.getPredefinedDictionary(cv.DICT_4X4_50); diff --git a/platforms/js/opencv_js.config.py b/platforms/js/opencv_js.config.py index c926a62f5d..69891ea71a 100644 --- a/platforms/js/opencv_js.config.py +++ b/platforms/js/opencv_js.config.py @@ -126,7 +126,8 @@ objdetect = {'': ['groupRectangles', 'getPredefinedDictionary', 'extendDictionar 'aruco_ArucoDetector': ['ArucoDetector', 'detectMarkers', 'refineDetectedMarkers', 'setDictionary', 'setDetectorParameters', 'setRefineParameters'], 'aruco_CharucoDetector': ['CharucoDetector', 'setBoard', 'setCharucoParameters', 'setDetectorParameters', 'setRefineParameters', 'detectBoard', 'detectDiamonds'], 'QRCodeDetectorAruco_Params': ['Params'], - 'QRCodeDetectorAruco': ['QRCodeDetectorAruco', 'decode', 'detect', 'detectAndDecode', 'detectMulti', 'decodeMulti', 'detectAndDecodeMulti', 'setDetectorParameters', 'setArucoParameters'] + 'QRCodeDetectorAruco': ['QRCodeDetectorAruco', 'decode', 'detect', 'detectAndDecode', 'detectMulti', 'decodeMulti', 'detectAndDecodeMulti', 'setDetectorParameters', 'setArucoParameters'], + 'barcode_BarcodeDetector': ['BarcodeDetector', 'decode', 'detect', 'detectAndDecode', 'detectMulti', 'decodeMulti', 'detectAndDecodeMulti', 'decodeWithType', 'detectAndDecodeWithType'] } video = {