js: include LUT support

This commit is contained in:
Alexander Alekhin 2023-09-09 03:19:45 +00:00
parent 1a8d37d19e
commit c319735d9b
5 changed files with 54 additions and 6 deletions

View File

@ -0,0 +1,41 @@
// This file is part of OpenCV project.
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
if (typeof module !== 'undefined' && module.exports) {
// The environment is Node.js
var cv = require('./opencv.js'); // eslint-disable-line no-var
}
QUnit.module('Core', {});
QUnit.test('test_LUT', function(assert) {
// test LUT
{
let src = cv.matFromArray(3, 3, cv.CV_8UC1, [255, 128, 0, 0, 128, 255, 1, 2, 254]);
let lutTable = [];
for (let i = 0; i < 256; i++)
{
lutTable[i] = 255 - i;
}
let lut = cv.matFromArray(1, 256, cv.CV_8UC1, lutTable);
let dst = new cv.Mat();
cv.LUT(src, lut, dst);
//console.log(dst.data);
assert.equal(dst.ucharAt(0), 0);
assert.equal(dst.ucharAt(1), 127);
assert.equal(dst.ucharAt(2), 255);
assert.equal(dst.ucharAt(3), 255);
assert.equal(dst.ucharAt(4), 127);
assert.equal(dst.ucharAt(5), 0);
assert.equal(dst.ucharAt(6), 254);
assert.equal(dst.ucharAt(7), 253);
assert.equal(dst.ucharAt(8), 1);
src.delete();
lut.delete();
dst.delete();
}
});

View File

@ -73,7 +73,7 @@ if (typeof module !== 'undefined' && module.exports) {
var cv = require('./opencv.js'); // eslint-disable-line no-var
}
QUnit.module('Core', {});
QUnit.module('CoreMat', {});
QUnit.test('test_mat_creation', function(assert) {
// Mat constructors.

View File

@ -52,12 +52,12 @@
if (window.cv instanceof Promise) {
window.cv.then((target) => {
window.cv = target;
//console.log(cv.getBuildInformation());
console.log(cv.getBuildInformation());
QUnit.start();
})
} else {
// for backward compatible
// console.log(cv.getBuildInformation());
console.log(cv.getBuildInformation());
QUnit.start();
}
},
@ -108,6 +108,7 @@
<script type="application/javascript" async src="opencv.js" onerror="opencvjs_LoadError()"></script>
<script type="application/javascript" src="test_mat.js"></script>
<script type="application/javascript" src="test_utils.js"></script>
<script type="application/javascript" src="test_core.js"></script>
<script type="application/javascript" src="test_imgproc.js"></script>
<script type="application/javascript" src="test_objdetect.js"></script>
<script type="application/javascript" src="test_video.js"></script>

View File

@ -44,10 +44,15 @@ testrunner.options.maxBlockDuration = 20000; // cause opencv_js.js need time to
testrunner.run(
{
code: 'opencv.js',
tests: ['test_mat.js', 'test_utils.js', 'test_imgproc.js',
'test_objdetect.js', 'test_video.js', 'test_features2d.js',
tests: ['test_mat.js',
'test_utils.js',
'test_core.js',
'test_imgproc.js',
'test_objdetect.js',
'test_video.js',
'test_features2d.js',
'test_photo.js',
'test_calib3d.js'
'test_calib3d.js',
],
},
function(err, report) {

View File

@ -9,6 +9,7 @@ core = {
'perspectiveTransform', 'polarToCart', 'pow', 'randn', 'randu', 'reduce', 'repeat', 'rotate', 'setIdentity', 'setRNGSeed',
'solve', 'solvePoly', 'split', 'sqrt', 'subtract', 'trace', 'transform', 'transpose', 'vconcat',
'setLogLevel', 'getLogLevel',
'LUT',
],
'Algorithm': [],
}