1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-31 08:13:04 +04:00

Merge pull request #19284 from Ziachnix:feature/js-qr-code-detector

Add QRCodeDetector to JavaScript Build

* ADD: js support for qrCodeDetector

- cherry picked commit to solve rebase error

* CHG. Revert haarcascade path

* FIX: Tests without images

* ADD: decodeCurved

* js(docs): don't require OPENCV_TEST_DATA_PATH

Co-authored-by: Alexander Alekhin <alexander.a.alekhin@gmail.com>
This commit is contained in:
Ziachnix
2021-03-13 13:52:44 +01:00
committed by GitHub
parent 7a8e171691
commit 960f501cc1
5 changed files with 54 additions and 6 deletions
+3 -4
View File
@@ -119,6 +119,7 @@ type_dict = {
'InputOutputArray': 'cv::Mat&',
'InputArrayOfArrays': 'const std::vector<cv::Mat>&',
'OutputArrayOfArrays': 'std::vector<cv::Mat>&',
'string': 'std::string',
'String': 'std::string',
'const String&':'const std::string&'
}
@@ -462,8 +463,7 @@ class JSWrapperGenerator(object):
ret_type = type_dict[ptr_type]
for key in type_dict:
if key in ret_type:
ret_type = ret_type.replace(key, type_dict[key])
ret_type = re.sub('(^|[^\w])' + key + '($|[^\w])', type_dict[key], ret_type)
arg_types = []
unwrapped_arg_types = []
for arg in variant.args:
@@ -567,7 +567,7 @@ class JSWrapperGenerator(object):
# consider the default parameter variants
args_num = len(variant.args) - j
if args_num in class_info.constructor_arg_num:
# FIXME: workaournd for constructor overload with same args number
# FIXME: workaround for constructor overload with same args number
# e.g. DescriptorMatcher
continue
class_info.constructor_arg_num.add(args_num)
@@ -627,7 +627,6 @@ class JSWrapperGenerator(object):
ret_type = 'void' if variant.rettype.strip() == '' else variant.rettype
ret_type = ret_type.strip()
if ret_type.startswith('Ptr'): #smart pointer
ptr_type = ret_type.replace('Ptr<', '').replace('>', '')
if ptr_type in type_dict:
+41
View File
@@ -159,3 +159,44 @@ QUnit.test('Cascade classification', function(assert) {
locations.delete();
}
});
QUnit.test('QR code detect and decode', function (assert) {
{
const detector = new cv.QRCodeDetector();
let mat = cv.Mat.ones(800, 600, cv.CV_8U);
assert.ok(mat);
// test detect
let points = new cv.Mat();
let qrCodeFound = detector.detect(mat, points);
assert.equal(points.rows, 0)
assert.equal(points.cols, 0)
assert.equal(qrCodeFound, false);
// test detectMult
qrCodeFound = detector.detectMulti(mat, points);
assert.equal(points.rows, 0)
assert.equal(points.cols, 0)
assert.equal(qrCodeFound, false);
// test decode (with random numbers)
let decodeTestPoints = cv.matFromArray(1, 4, cv.CV_32FC2, [10, 20, 30, 40, 60, 80, 90, 100]);
let qrCodeContent = detector.decode(mat, decodeTestPoints);
assert.equal(typeof qrCodeContent, 'string');
assert.equal(qrCodeContent, '');
//test detectAndDecode
qrCodeContent = detector.detectAndDecode(mat);
assert.equal(typeof qrCodeContent, 'string');
assert.equal(qrCodeContent, '');
// test decodeCurved
qrCodeContent = detector.decodeCurved(mat, decodeTestPoints);
assert.equal(typeof qrCodeContent, 'string');
assert.equal(qrCodeContent, '');
decodeTestPoints.delete();
points.delete();
mat.delete();
}
});