add part of opencv
This commit is contained in:
12
Lib/opencv/sources/modules/js/test/.eslintrc.json
Normal file
12
Lib/opencv/sources/modules/js/test/.eslintrc.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"extends": "google",
|
||||
"parserOptions": {
|
||||
"ecmaVersion": 6
|
||||
},
|
||||
"rules": {
|
||||
"max-len": ["error", 100, {"ignoreUrls": true}],
|
||||
"quotes": ["error", "single"],
|
||||
"indent": ["error", 4, {"ArrayExpression": "first",
|
||||
"CallExpression": {"arguments": "first"}}]
|
||||
}
|
||||
}
|
||||
28
Lib/opencv/sources/modules/js/test/package.json
Normal file
28
Lib/opencv/sources/modules/js/test/package.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "opencv_js_tests",
|
||||
"description": "Tests for opencv js bindings",
|
||||
"version": "1.0.1",
|
||||
"dependencies": {
|
||||
"ansi-colors": "^4.1.1",
|
||||
"minimist": "^1.2.0",
|
||||
"node-qunit": "latest"
|
||||
},
|
||||
"devDependencies": {
|
||||
"eslint": "latest",
|
||||
"eslint-config-google": "latest"
|
||||
},
|
||||
"scripts": {
|
||||
"test": "node tests.js"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/opencv/opencv.git"
|
||||
},
|
||||
"keywords": [],
|
||||
"author": "",
|
||||
"license": "BSD-3-Clause",
|
||||
"bugs": {
|
||||
"url": "https://github.com/opencv/opencv/issues"
|
||||
},
|
||||
"homepage": "https://github.com/opencv/opencv"
|
||||
}
|
||||
214
Lib/opencv/sources/modules/js/test/run_puppeteer.js
Normal file
214
Lib/opencv/sources/modules/js/test/run_puppeteer.js
Normal file
@@ -0,0 +1,214 @@
|
||||
try {
|
||||
require('puppeteer')
|
||||
} catch (e) {
|
||||
console.error(
|
||||
"\nFATAL ERROR:" +
|
||||
"\n Package 'puppeteer' is not available." +
|
||||
"\n Run 'npm install --no-save puppeteer' before running this script" +
|
||||
"\n * You may use PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=1 environment variable to avoid automatic Chromium downloading" +
|
||||
"\n (specify own Chromium/Chrome version through PUPPETEER_EXECUTABLE_PATH=`which google-chrome` environment variable)" +
|
||||
"\n");
|
||||
process.exit(1);
|
||||
}
|
||||
const puppeteer = require('puppeteer')
|
||||
const colors = require("ansi-colors")
|
||||
const path = require("path");
|
||||
const fs = require("fs");
|
||||
const http = require("http");
|
||||
|
||||
run_main(require('minimist')(process.argv.slice(2)));
|
||||
|
||||
async function run_main(o = {}) {
|
||||
try {
|
||||
await main(o);
|
||||
console.magenta("FATAL: Unexpected exit!");
|
||||
process.exit(1);
|
||||
} catch (e) {
|
||||
console.error(colors.magenta("FATAL: Unexpected exception!"));
|
||||
console.error(e);
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
async function main(o = {}) {
|
||||
o = Object.assign({}, {
|
||||
buildFolder: __dirname,
|
||||
port: 8080,
|
||||
debug: false,
|
||||
noHeadless: false,
|
||||
serverPrefix: `http://localhost`,
|
||||
noExit: false,
|
||||
screenshot: undefined,
|
||||
help: false,
|
||||
noTryCatch: false,
|
||||
maxBlockDuration: 30000
|
||||
}, o)
|
||||
if (typeof o.screenshot == 'string' && o.screenshot == 'false') {
|
||||
console.log(colors.red('ERROR: misused screenshot option, use --no-screenshot instead'));
|
||||
}
|
||||
if (o.noExit) {
|
||||
o.maxBlockDuration = 999999999
|
||||
}
|
||||
o.debug && console.log('Current Options', o);
|
||||
if (o.help) {
|
||||
printHelpAndExit();
|
||||
}
|
||||
const serverAddress = `${o.serverPrefix}:${o.port}`
|
||||
const url = `${serverAddress}/tests.html${o.noTryCatch ? '?notrycatch=1' : ''}`;
|
||||
if (!fs.existsSync(o.buildFolder)) {
|
||||
console.error(`Expected folder "${o.buildFolder}" to exists. Aborting`);
|
||||
}
|
||||
o.debug && debug('Server Listening at ' + url);
|
||||
const server = await staticServer(o.buildFolder, o.port, m => debug, m => error);
|
||||
o.debug && debug(`Browser launching ${!o.noHeadless ? 'headless' : 'not headless'}`);
|
||||
const browser = await puppeteer.launch({ headless: !o.noHeadless });
|
||||
const page = await browser.newPage();
|
||||
page.on('console', e => {
|
||||
locationMsg = formatMessage(`${e.location().url}:${e.location().lineNumber}:${e.location().columnNumber}`);
|
||||
if (e.type() === 'error') {
|
||||
console.log(colors.red(formatMessage('' + e.text(), `-- ERROR:${locationMsg}: `, )));
|
||||
}
|
||||
else if (o.debug) {
|
||||
o.debug && console.log(colors.grey(formatMessage('' + e.text(), `-- ${locationMsg}: `)));
|
||||
}
|
||||
});
|
||||
o.debug && debug(`Opening page address ${url}`);
|
||||
await page.goto(url);
|
||||
await page.waitForFunction(() => (document.querySelector(`#qunit-testresult`) && document.querySelector(`#qunit-testresult`).textContent || '').trim().toLowerCase().startsWith('tests completed'));
|
||||
const text = await getText(`#qunit-testresult`);
|
||||
if (!text) {
|
||||
return await fail(`An error occurred extracting test results. Check the build folder ${o.buildFolder} is correct and has build with tests enabled.`);
|
||||
}
|
||||
o.debug && debug(colors.blackBright("* UserAgent: " + await getText('#qunit-userAgent')));
|
||||
const testFailed = !text.includes(' 0 failed');
|
||||
if (testFailed && !o.debug) {
|
||||
process.stdout.write(colors.grey("* Use '--debug' parameter to see details of failed tests.\n"));
|
||||
}
|
||||
if (o.screenshot || (o.screenshot === undefined && testFailed)) {
|
||||
await page.screenshot({ path: 'screenshot.png', fullPage: 'true' });
|
||||
process.stdout.write(colors.grey(`* Screenshot taken: ${o.buildFolder}/screenshot.png\n`));
|
||||
}
|
||||
if (testFailed) {
|
||||
const report = await failReport();
|
||||
process.stdout.write(`
|
||||
${colors.red.bold.underline('Failed tests ! :(')}
|
||||
|
||||
${colors.redBright(colors.symbols.cross + ' ' + report.join(`\n${colors.symbols.cross} `))}
|
||||
|
||||
${colors.redBright(`=== Summary ===\n${text}`)}
|
||||
`);
|
||||
}
|
||||
else {
|
||||
process.stdout.write(colors.green(`
|
||||
${colors.symbols.check} No Errors :)
|
||||
|
||||
=== Summary ===\n${text}
|
||||
`));
|
||||
}
|
||||
if (o.noExit) {
|
||||
while (true) {
|
||||
await new Promise(r => setTimeout(r, 5000));
|
||||
}
|
||||
}
|
||||
await server && server.close();
|
||||
await browser.close();
|
||||
process.exit(testFailed ? 1 : 0);
|
||||
|
||||
async function getText(s) {
|
||||
return await page.evaluate((s) => (document.querySelector(s) && document.querySelector(s).innerText) || ''.trim(), s);
|
||||
}
|
||||
async function failReport() {
|
||||
const failures = await page.evaluate(() => Array.from(document.querySelectorAll('#qunit-tests .fail')).filter(e => e.querySelector('.module-name')).map(e => ({
|
||||
moduleName: e.querySelector('.module-name') && e.querySelector('.module-name').textContent,
|
||||
testName: e.querySelector('.test-name') && e.querySelector('.test-name').textContent,
|
||||
expected: e.querySelector('.test-expected pre') && e.querySelector('.test-expected pre').textContent,
|
||||
actual: e.querySelector('.test-actual pre') && e.querySelector('.test-actual pre').textContent,
|
||||
code: e.querySelector('.test-source') && e.querySelector('.test-source').textContent.replace("Source: at ", ""),
|
||||
})));
|
||||
return failures.map(f => `${f.moduleName}: ${f.testName} (${formatMessage(f.code)})`);
|
||||
}
|
||||
async function fail(s) {
|
||||
await failReport();
|
||||
process.stdout.write(colors.red(s) + '\n');
|
||||
if (o.screenshot || o.screenshot === undefined) {
|
||||
await page.screenshot({ path: 'screenshot.png', fullPage: 'true' });
|
||||
process.stdout.write(colors.grey(`* Screenshot taken: ${o.buildFolder}/screenshot.png\n`));
|
||||
}
|
||||
process.exit(1);
|
||||
}
|
||||
async function debug(s) {
|
||||
process.stdout.write(s + '\n');
|
||||
}
|
||||
async function error(s) {
|
||||
process.stdout.write(s + '\n');
|
||||
}
|
||||
function formatMessage(message, prefix) {
|
||||
prefix = prefix || '';
|
||||
return prefix + ('' + message).split('\n').map(l => l.replace(serverAddress, o.buildFolder)).join('\n' + prefix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function printHelpAndExit() {
|
||||
console.log(`
|
||||
Usage:
|
||||
|
||||
# First, remember to build opencv.js with tests enabled:
|
||||
${colors.blueBright(`python ./platforms/js/build_js.py build_js --build_test`)}
|
||||
|
||||
# Install the tool locally (needed only once) and run it
|
||||
${colors.blueBright(`cd build_js/bin`)}
|
||||
${colors.blueBright(`npm install`)}
|
||||
${colors.blueBright(`node run_puppeteer`)}
|
||||
|
||||
By default will run a headless browser silently printing a small report in the terminal.
|
||||
But it could used to debug the tests in the browser, take screenshots, global tool or
|
||||
targeting external servers exposing the tests.
|
||||
|
||||
TIP: you could install the tool globally (npm install --global build_js/bin) to execute it from any local folder.
|
||||
|
||||
# Options
|
||||
|
||||
* port?: number. Default 8080
|
||||
* buildFolder?: string. Default __dirname (this folder)
|
||||
* debug?: boolean. Default false
|
||||
* noHeadless?: boolean. Default false
|
||||
* serverPrefix?: string . Default http://localhost
|
||||
* help?: boolean
|
||||
* screenshot?: boolean . Make screenshot on failure by default. Use --no-screenshot to disable screenshots completely.
|
||||
* noExit?: boolean default false. If true it will keep running the server - together with noHeadless you can debug in the browser.
|
||||
* noTryCatch?: boolean will disable Qunit tryCatch - so exceptions are dump to stdout rather than in the browser.
|
||||
* maxBlockDuration: QUnit timeout. If noExit is given then is infinity.
|
||||
`);
|
||||
process.exit(0);
|
||||
}
|
||||
|
||||
async function staticServer(basePath, port, onFound, onNotFound) {
|
||||
return new Promise(async (resolve) => {
|
||||
const server = http.createServer((req, res) => {
|
||||
var url = resolveUrl(req.url);
|
||||
onFound && onFound(url);
|
||||
var stream = fs.createReadStream(path.join(basePath, url || ''));
|
||||
stream.on('error', function () {
|
||||
onNotFound && onNotFound(url);
|
||||
res.writeHead(404);
|
||||
res.end();
|
||||
});
|
||||
stream.pipe(res);
|
||||
}).listen(port);
|
||||
server.on('listening', () => {
|
||||
resolve(server);
|
||||
});
|
||||
});
|
||||
function resolveUrl(url = '') {
|
||||
var i = url.indexOf('?');
|
||||
if (i != -1) {
|
||||
url = url.substr(0, i);
|
||||
}
|
||||
i = url.indexOf('#');
|
||||
if (i != -1) {
|
||||
url = url.substr(0, i);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
}
|
||||
91
Lib/opencv/sources/modules/js/test/test_calib3d.js
Normal file
91
Lib/opencv/sources/modules/js/test/test_calib3d.js
Normal file
@@ -0,0 +1,91 @@
|
||||
// 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('Camera Calibration and 3D Reconstruction', {});
|
||||
|
||||
QUnit.test('constants', function(assert) {
|
||||
assert.strictEqual(typeof cv.LMEDS, 'number');
|
||||
assert.strictEqual(typeof cv.RANSAC, 'number');
|
||||
assert.strictEqual(typeof cv.RHO, 'number');
|
||||
});
|
||||
|
||||
QUnit.test('findHomography', function(assert) {
|
||||
let srcPoints = cv.matFromArray(4, 1, cv.CV_32FC2, [
|
||||
56,
|
||||
65,
|
||||
368,
|
||||
52,
|
||||
28,
|
||||
387,
|
||||
389,
|
||||
390,
|
||||
]);
|
||||
let dstPoints = cv.matFromArray(4, 1, cv.CV_32FC2, [
|
||||
0,
|
||||
0,
|
||||
300,
|
||||
0,
|
||||
0,
|
||||
300,
|
||||
300,
|
||||
300,
|
||||
]);
|
||||
|
||||
const mat = cv.findHomography(srcPoints, dstPoints);
|
||||
|
||||
assert.ok(mat instanceof cv.Mat);
|
||||
});
|
||||
|
||||
QUnit.test('Rodrigues', function(assert) {
|
||||
// Converts a rotation matrix to a rotation vector and vice versa
|
||||
// data64F is the output array
|
||||
const rvec0 = cv.matFromArray(1, 3, cv.CV_64F, [1,1,1]);
|
||||
let rMat0 = new cv.Mat();
|
||||
let rvec1 = new cv.Mat();
|
||||
|
||||
// Args: input Mat, output Mat. The function mutates the output Mat, so the function does not return anything.
|
||||
// cv.Rodrigues (InputArray=src, OutputArray=dst, jacobian=0)
|
||||
// https://docs.opencv.org/2.4/modules/calib3d/doc/camera_calibration_and_3d_reconstruction.html#void%20Rodrigues(InputArray%20src,%20OutputArray%20dst,%20OutputArray%20jacobian)
|
||||
// vec to Mat, starting number is 3 long and each element is 1.
|
||||
cv.Rodrigues(rvec0, rMat0);
|
||||
|
||||
assert.ok(rMat0.data64F.length == 9);
|
||||
assert.ok(0.23 > rMat0.data64F[0] > 0.22);
|
||||
|
||||
// convert Mat to Vec, should be same as what we started with, 3 long and each item should be a 1.
|
||||
cv.Rodrigues(rMat0, rvec1);
|
||||
|
||||
assert.ok(rvec1.data64F.length == 3);
|
||||
assert.ok(1.01 > rvec1.data64F[0] > 0.9);
|
||||
// Answer should be around 1: 0.9999999999999999
|
||||
});
|
||||
|
||||
QUnit.test('estimateAffine2D', function(assert) {
|
||||
const inputs = cv.matFromArray(4, 1, cv.CV_32FC2, [
|
||||
1, 1,
|
||||
80, 0,
|
||||
0, 80,
|
||||
80, 80
|
||||
]);
|
||||
const outputs = cv.matFromArray(4, 1, cv.CV_32FC2, [
|
||||
21, 51,
|
||||
70, 77,
|
||||
40, 40,
|
||||
10, 70
|
||||
]);
|
||||
const M = cv.estimateAffine2D(inputs, outputs);
|
||||
assert.ok(M instanceof cv.Mat);
|
||||
assert.deepEqual(Array.from(M.data), [
|
||||
23, 55, 97, 126, 87, 139, 227, 63, 0, 0,
|
||||
0, 0, 0, 0, 232, 191, 71, 246, 12, 68,
|
||||
165, 35, 53, 64, 99, 56, 27, 66, 14, 254,
|
||||
212, 63, 103, 102, 102, 102, 102, 102, 182, 191,
|
||||
195, 252, 174, 22, 55, 97, 73, 64
|
||||
]);
|
||||
});
|
||||
115
Lib/opencv/sources/modules/js/test/test_features2d.js
Normal file
115
Lib/opencv/sources/modules/js/test/test_features2d.js
Normal file
@@ -0,0 +1,115 @@
|
||||
// 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
|
||||
}
|
||||
|
||||
function generateTestFrame(width, height) {
|
||||
let w = width || 200;
|
||||
let h = height || 200;
|
||||
let img = new cv.Mat(h, w, cv.CV_8UC1, new cv.Scalar(0, 0, 0, 0));
|
||||
let s = new cv.Scalar(255, 255, 255, 255);
|
||||
let s128 = new cv.Scalar(128, 128, 128, 128);
|
||||
let rect = new cv.Rect(w / 4, h / 4, w / 2, h / 2);
|
||||
img.roi(rect).setTo(s);
|
||||
img.roi(new cv.Rect(w / 2 - w / 8, h / 2 - h / 8, w / 4, h / 4)).setTo(s128);
|
||||
cv.rectangle(img, new cv.Point(w / 8, h / 8), new cv.Point(w - w / 8, h - h / 8), s, 5);
|
||||
cv.rectangle(img, new cv.Point(w / 5, h / 5), new cv.Point(w - w / 5, h - h / 5), s128, 3);
|
||||
cv.line(img, new cv.Point(-w, 0), new cv.Point(w / 2, h / 2), s128, 5);
|
||||
cv.line(img, new cv.Point(2*w, 0), new cv.Point(w / 2, h / 2), s, 5);
|
||||
return img;
|
||||
}
|
||||
|
||||
QUnit.module('Features2D', {});
|
||||
QUnit.test('Detectors', function(assert) {
|
||||
let image = generateTestFrame();
|
||||
|
||||
let kp = new cv.KeyPointVector();
|
||||
|
||||
let orb = new cv.ORB();
|
||||
orb.detect(image, kp);
|
||||
assert.equal(kp.size(), 67, 'ORB');
|
||||
|
||||
let mser = new cv.MSER();
|
||||
mser.detect(image, kp);
|
||||
assert.equal(kp.size(), 7, 'MSER');
|
||||
|
||||
let brisk = new cv.BRISK();
|
||||
brisk.detect(image, kp);
|
||||
assert.equal(kp.size(), 191, 'BRISK');
|
||||
|
||||
let ffd = new cv.FastFeatureDetector();
|
||||
ffd.detect(image, kp);
|
||||
assert.equal(kp.size(), 12, 'FastFeatureDetector');
|
||||
|
||||
let afd = new cv.AgastFeatureDetector();
|
||||
afd.detect(image, kp);
|
||||
assert.equal(kp.size(), 67, 'AgastFeatureDetector');
|
||||
|
||||
let gftt = new cv.GFTTDetector();
|
||||
gftt.detect(image, kp);
|
||||
assert.equal(kp.size(), 168, 'GFTTDetector');
|
||||
|
||||
let kaze = new cv.KAZE();
|
||||
kaze.detect(image, kp);
|
||||
assert.equal(kp.size(), 159, 'KAZE');
|
||||
|
||||
let akaze = new cv.AKAZE();
|
||||
akaze.detect(image, kp);
|
||||
assert.equal(kp.size(), 53, 'AKAZE');
|
||||
});
|
||||
|
||||
QUnit.test('BFMatcher', function(assert) {
|
||||
// Generate key points.
|
||||
let image = generateTestFrame();
|
||||
|
||||
let kp = new cv.KeyPointVector();
|
||||
let descriptors = new cv.Mat();
|
||||
let orb = new cv.ORB();
|
||||
orb.detectAndCompute(image, new cv.Mat(), kp, descriptors);
|
||||
|
||||
assert.equal(kp.size(), 67);
|
||||
|
||||
// Run a matcher.
|
||||
let dm = new cv.DMatchVector();
|
||||
let matcher = new cv.BFMatcher();
|
||||
matcher.match(descriptors, descriptors, dm);
|
||||
|
||||
assert.equal(dm.size(), 67);
|
||||
});
|
||||
|
||||
QUnit.test('Drawing', function(assert) {
|
||||
// Generate key points.
|
||||
let image = generateTestFrame();
|
||||
|
||||
let kp = new cv.KeyPointVector();
|
||||
let descriptors = new cv.Mat();
|
||||
let orb = new cv.ORB();
|
||||
orb.detectAndCompute(image, new cv.Mat(), kp, descriptors);
|
||||
assert.equal(kp.size(), 67);
|
||||
|
||||
let dst = new cv.Mat();
|
||||
cv.drawKeypoints(image, kp, dst);
|
||||
assert.equal(dst.rows, image.rows);
|
||||
assert.equal(dst.cols, image.cols);
|
||||
|
||||
// Run a matcher.
|
||||
let dm = new cv.DMatchVector();
|
||||
let matcher = new cv.BFMatcher();
|
||||
matcher.match(descriptors, descriptors, dm);
|
||||
assert.equal(dm.size(), 67);
|
||||
|
||||
cv.drawMatches(image, kp, image, kp, dm, dst);
|
||||
assert.equal(dst.rows, image.rows);
|
||||
assert.equal(dst.cols, 2 * image.cols);
|
||||
|
||||
dm = new cv.DMatchVectorVector();
|
||||
matcher.knnMatch(descriptors, descriptors, dm, 2);
|
||||
assert.equal(dm.size(), 67);
|
||||
cv.drawMatchesKnn(image, kp, image, kp, dm, dst);
|
||||
assert.equal(dst.rows, image.rows);
|
||||
assert.equal(dst.cols, 2 * image.cols);
|
||||
});
|
||||
979
Lib/opencv/sources/modules/js/test/test_imgproc.js
Normal file
979
Lib/opencv/sources/modules/js/test/test_imgproc.js
Normal file
@@ -0,0 +1,979 @@
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
// Author: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
|
||||
//
|
||||
// LICENSE AGREEMENT
|
||||
// Copyright (c) 2015 The Regents of the University of California (Regents)
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the University nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
// The environment is Node.js
|
||||
var cv = require('./opencv.js'); // eslint-disable-line no-var
|
||||
}
|
||||
|
||||
QUnit.module('Image Processing', {});
|
||||
|
||||
QUnit.test('test_imgProc', function(assert) {
|
||||
// calcHist
|
||||
{
|
||||
let vec1 = new cv.Mat.ones(new cv.Size(20, 20), cv.CV_8UC1); // eslint-disable-line new-cap
|
||||
let source = new cv.MatVector();
|
||||
source.push_back(vec1);
|
||||
let channels = [0];
|
||||
let histSize = [256];
|
||||
let ranges =[0, 256];
|
||||
|
||||
let hist = new cv.Mat();
|
||||
let mask = new cv.Mat();
|
||||
let binSize = cv._malloc(4);
|
||||
let binView = new Int32Array(cv.HEAP8.buffer, binSize);
|
||||
binView[0] = 10;
|
||||
cv.calcHist(source, channels, mask, hist, histSize, ranges, false);
|
||||
|
||||
// hist should contains a N X 1 array.
|
||||
let size = hist.size();
|
||||
assert.equal(size.height, 256);
|
||||
assert.equal(size.width, 1);
|
||||
|
||||
// default parameters
|
||||
cv.calcHist(source, channels, mask, hist, histSize, ranges);
|
||||
size = hist.size();
|
||||
assert.equal(size.height, 256);
|
||||
assert.equal(size.width, 1);
|
||||
|
||||
// Do we need to verify data in histogram?
|
||||
// let dataView = hist.data;
|
||||
|
||||
// Free resource
|
||||
cv._free(binSize);
|
||||
mask.delete();
|
||||
hist.delete();
|
||||
}
|
||||
|
||||
// cvtColor
|
||||
{
|
||||
let source = new cv.Mat(10, 10, cv.CV_8UC3);
|
||||
let dest = new cv.Mat();
|
||||
|
||||
cv.cvtColor(source, dest, cv.COLOR_BGR2GRAY, 0);
|
||||
assert.equal(dest.channels(), 1);
|
||||
|
||||
cv.cvtColor(source, dest, cv.COLOR_BGR2GRAY);
|
||||
assert.equal(dest.channels(), 1);
|
||||
|
||||
cv.cvtColor(source, dest, cv.COLOR_BGR2BGRA, 0);
|
||||
assert.equal(dest.channels(), 4);
|
||||
|
||||
cv.cvtColor(source, dest, cv.COLOR_BGR2BGRA);
|
||||
assert.equal(dest.channels(), 4);
|
||||
|
||||
dest.delete();
|
||||
source.delete();
|
||||
}
|
||||
// equalizeHist
|
||||
{
|
||||
let source = new cv.Mat(10, 10, cv.CV_8UC1);
|
||||
let dest = new cv.Mat();
|
||||
|
||||
cv.equalizeHist(source, dest);
|
||||
|
||||
// eualizeHist changes the content of a image, but does not alter meta data
|
||||
// of it.
|
||||
assert.equal(source.channels(), dest.channels());
|
||||
assert.equal(source.type(), dest.type());
|
||||
|
||||
dest.delete();
|
||||
source.delete();
|
||||
}
|
||||
|
||||
// floodFill
|
||||
{
|
||||
let center = new cv.Point(5, 5);
|
||||
let rect = new cv.Rect(0, 0, 0, 0);
|
||||
let img = new cv.Mat.zeros(10, 10, cv.CV_8UC1);
|
||||
let color = new cv.Scalar (255);
|
||||
cv.circle(img, center, 3, color, 1);
|
||||
|
||||
let edge = new cv.Mat();
|
||||
cv.Canny(img, edge, 100, 255);
|
||||
cv.copyMakeBorder(edge, edge, 1, 1, 1, 1, cv.BORDER_REPLICATE);
|
||||
|
||||
let expected_img_data = new Uint8Array([
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 255, 0, 0, 0, 0,
|
||||
0, 0, 0, 255, 255, 255, 255, 255, 0, 0,
|
||||
0, 0, 0, 255, 0, 255, 0, 255, 0, 0,
|
||||
0, 0, 255, 255, 255, 255, 0, 0, 255, 0,
|
||||
0, 0, 0, 255, 0, 0, 0, 255, 0, 0,
|
||||
0, 0, 0, 255, 255, 0, 255, 255, 0, 0,
|
||||
0, 0, 0, 0, 0, 255, 0, 0, 0, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
|
||||
|
||||
let img_elem = 10*10*1;
|
||||
let expected_img_data_ptr = cv._malloc(img_elem);
|
||||
let expected_img_data_heap = new Uint8Array(cv.HEAPU8.buffer,
|
||||
expected_img_data_ptr,
|
||||
img_elem);
|
||||
expected_img_data_heap.set(new Uint8Array(expected_img_data.buffer));
|
||||
|
||||
let expected_img = new cv.Mat( 10, 10, cv.CV_8UC1, expected_img_data_ptr, 0);
|
||||
|
||||
let expected_rect = new cv.Rect(3,3,3,3);
|
||||
|
||||
let compare_result = new cv.Mat(10, 10, cv.CV_8UC1);
|
||||
|
||||
cv.floodFill(img, edge, center, color, rect);
|
||||
|
||||
cv.compare (img, expected_img, compare_result, cv.CMP_EQ);
|
||||
|
||||
// expect every pixels are the same.
|
||||
assert.equal (cv.countNonZero(compare_result), img.total());
|
||||
assert.equal (rect.x, expected_rect.x);
|
||||
assert.equal (rect.y, expected_rect.y);
|
||||
assert.equal (rect.width, expected_rect.width);
|
||||
assert.equal (rect.height, expected_rect.height);
|
||||
|
||||
img.delete();
|
||||
edge.delete();
|
||||
expected_img.delete();
|
||||
compare_result.delete();
|
||||
}
|
||||
|
||||
// fillPoly
|
||||
{
|
||||
let img_width = 6;
|
||||
let img_height = 6;
|
||||
|
||||
let img = new cv.Mat.zeros(img_height, img_width, cv.CV_8UC1);
|
||||
|
||||
let npts = 4;
|
||||
let square_point_data = new Uint8Array([
|
||||
1, 1,
|
||||
4, 1,
|
||||
4, 4,
|
||||
1, 4]);
|
||||
let square_points = cv.matFromArray(npts, 1, cv.CV_32SC2, square_point_data);
|
||||
let pts = new cv.MatVector();
|
||||
pts.push_back (square_points);
|
||||
let color = new cv.Scalar (255);
|
||||
|
||||
let expected_img_data = new Uint8Array([
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 255, 255, 255, 255, 0,
|
||||
0, 255, 255, 255, 255, 0,
|
||||
0, 255, 255, 255, 255, 0,
|
||||
0, 255, 255, 255, 255, 0,
|
||||
0, 0, 0, 0, 0, 0]);
|
||||
let expected_img = cv.matFromArray(img_height, img_width, cv.CV_8UC1, expected_img_data);
|
||||
|
||||
cv.fillPoly(img, pts, color);
|
||||
|
||||
let compare_result = new cv.Mat(img_height, img_width, cv.CV_8UC1);
|
||||
|
||||
cv.compare (img, expected_img, compare_result, cv.CMP_EQ);
|
||||
|
||||
// expect every pixels are the same.
|
||||
assert.equal (cv.countNonZero(compare_result), img.total());
|
||||
|
||||
img.delete();
|
||||
square_points.delete();
|
||||
pts.delete();
|
||||
expected_img.delete();
|
||||
compare_result.delete();
|
||||
}
|
||||
|
||||
// fillConvexPoly
|
||||
{
|
||||
let img_width = 6;
|
||||
let img_height = 6;
|
||||
|
||||
let img = new cv.Mat.zeros(img_height, img_width, cv.CV_8UC1);
|
||||
|
||||
let npts = 4;
|
||||
let square_point_data = new Uint8Array([
|
||||
1, 1,
|
||||
4, 1,
|
||||
4, 4,
|
||||
1, 4]);
|
||||
let square_points = cv.matFromArray(npts, 1, cv.CV_32SC2, square_point_data);
|
||||
let color = new cv.Scalar (255);
|
||||
|
||||
let expected_img_data = new Uint8Array([
|
||||
0, 0, 0, 0, 0, 0,
|
||||
0, 255, 255, 255, 255, 0,
|
||||
0, 255, 255, 255, 255, 0,
|
||||
0, 255, 255, 255, 255, 0,
|
||||
0, 255, 255, 255, 255, 0,
|
||||
0, 0, 0, 0, 0, 0]);
|
||||
let expected_img = cv.matFromArray(img_height, img_width, cv.CV_8UC1, expected_img_data);
|
||||
|
||||
cv.fillConvexPoly(img, square_points, color);
|
||||
|
||||
let compare_result = new cv.Mat(img_height, img_width, cv.CV_8UC1);
|
||||
|
||||
cv.compare (img, expected_img, compare_result, cv.CMP_EQ);
|
||||
|
||||
// expect every pixels are the same.
|
||||
assert.equal (cv.countNonZero(compare_result), img.total());
|
||||
|
||||
img.delete();
|
||||
square_points.delete();
|
||||
expected_img.delete();
|
||||
compare_result.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_segmentation', function(assert) {
|
||||
const THRESHOLD = 127.0;
|
||||
const THRESHOLD_MAX = 210.0;
|
||||
|
||||
// threshold
|
||||
{
|
||||
let source = new cv.Mat(1, 5, cv.CV_8UC1);
|
||||
let sourceView = source.data;
|
||||
sourceView[0] = 0; // < threshold
|
||||
sourceView[1] = 100; // < threshold
|
||||
sourceView[2] = 200; // > threshold
|
||||
|
||||
let dest = new cv.Mat();
|
||||
|
||||
cv.threshold(source, dest, THRESHOLD, THRESHOLD_MAX, cv.THRESH_BINARY);
|
||||
|
||||
let destView = dest.data;
|
||||
assert.equal(destView[0], 0);
|
||||
assert.equal(destView[1], 0);
|
||||
assert.equal(destView[2], THRESHOLD_MAX);
|
||||
}
|
||||
|
||||
// adaptiveThreshold
|
||||
{
|
||||
let source = cv.Mat.zeros(1, 5, cv.CV_8UC1);
|
||||
let sourceView = source.data;
|
||||
sourceView[0] = 50;
|
||||
sourceView[1] = 150;
|
||||
sourceView[2] = 200;
|
||||
|
||||
let dest = new cv.Mat();
|
||||
const C = 0;
|
||||
const blockSize = 3;
|
||||
cv.adaptiveThreshold(source, dest, THRESHOLD_MAX,
|
||||
cv.ADAPTIVE_THRESH_MEAN_C, cv.THRESH_BINARY, blockSize, C);
|
||||
|
||||
let destView = dest.data;
|
||||
assert.equal(destView[0], 0);
|
||||
assert.equal(destView[1], THRESHOLD_MAX);
|
||||
assert.equal(destView[2], THRESHOLD_MAX);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_shape', function(assert) {
|
||||
// moments
|
||||
{
|
||||
let points = new cv.Mat(1, 4, cv.CV_32SC2);
|
||||
let data32S = points.data32S;
|
||||
data32S[0]=50;
|
||||
data32S[1]=56;
|
||||
data32S[2]=53;
|
||||
data32S[3]=53;
|
||||
data32S[4]=46;
|
||||
data32S[5]=54;
|
||||
data32S[6]=49;
|
||||
data32S[7]=51;
|
||||
|
||||
let m = cv.moments(points, false);
|
||||
let area = cv.contourArea(points, false);
|
||||
|
||||
assert.equal(m.m00, 0);
|
||||
assert.equal(m.m01, 0);
|
||||
assert.equal(m.m10, 0);
|
||||
assert.equal(area, 0);
|
||||
|
||||
// default parameters
|
||||
m = cv.moments(points);
|
||||
area = cv.contourArea(points);
|
||||
assert.equal(m.m00, 0);
|
||||
assert.equal(m.m01, 0);
|
||||
assert.equal(m.m10, 0);
|
||||
assert.equal(area, 0);
|
||||
|
||||
points.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_min_enclosing', function(assert) {
|
||||
{
|
||||
let points = new cv.Mat(4, 1, cv.CV_32FC2);
|
||||
|
||||
points.data32F[0] = 0;
|
||||
points.data32F[1] = 0;
|
||||
points.data32F[2] = 1;
|
||||
points.data32F[3] = 0;
|
||||
points.data32F[4] = 1;
|
||||
points.data32F[5] = 1;
|
||||
points.data32F[6] = 0;
|
||||
points.data32F[7] = 1;
|
||||
|
||||
let circle = cv.minEnclosingCircle(points);
|
||||
|
||||
assert.deepEqual(circle.center, {x: 0.5, y: 0.5});
|
||||
assert.ok(Math.abs(circle.radius - Math.sqrt(2) / 2) < 0.001);
|
||||
|
||||
points.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_filter', function(assert) {
|
||||
// blur
|
||||
{
|
||||
let mat1 = cv.Mat.ones(5, 5, cv.CV_8UC3);
|
||||
let mat2 = new cv.Mat();
|
||||
|
||||
cv.blur(mat1, mat2, {height: 3, width: 3}, {x: -1, y: -1}, cv.BORDER_DEFAULT);
|
||||
|
||||
// Verify result.
|
||||
let size = mat2.size();
|
||||
assert.equal(mat2.channels(), 3);
|
||||
assert.equal(size.height, 5);
|
||||
assert.equal(size.width, 5);
|
||||
|
||||
cv.blur(mat1, mat2, {height: 3, width: 3}, {x: -1, y: -1});
|
||||
|
||||
// Verify result.
|
||||
size = mat2.size();
|
||||
assert.equal(mat2.channels(), 3);
|
||||
assert.equal(size.height, 5);
|
||||
assert.equal(size.width, 5);
|
||||
|
||||
cv.blur(mat1, mat2, {height: 3, width: 3});
|
||||
|
||||
// Verify result.
|
||||
size = mat2.size();
|
||||
assert.equal(mat2.channels(), 3);
|
||||
assert.equal(size.height, 5);
|
||||
assert.equal(size.width, 5);
|
||||
|
||||
mat1.delete();
|
||||
mat2.delete();
|
||||
}
|
||||
|
||||
// GaussianBlur
|
||||
{
|
||||
let mat1 = cv.Mat.ones(7, 7, cv.CV_8UC1);
|
||||
let mat2 = new cv.Mat();
|
||||
|
||||
cv.GaussianBlur(mat1, mat2, new cv.Size(3, 3), 0, 0, // eslint-disable-line new-cap
|
||||
cv.BORDER_DEFAULT);
|
||||
|
||||
// Verify result.
|
||||
let size = mat2.size();
|
||||
assert.equal(mat2.channels(), 1);
|
||||
assert.equal(size.height, 7);
|
||||
assert.equal(size.width, 7);
|
||||
}
|
||||
|
||||
// medianBlur
|
||||
{
|
||||
let mat1 = cv.Mat.ones(9, 9, cv.CV_8UC3);
|
||||
let mat2 = new cv.Mat();
|
||||
|
||||
cv.medianBlur(mat1, mat2, 3);
|
||||
|
||||
// Verify result.
|
||||
let size = mat2.size();
|
||||
assert.equal(mat2.channels(), 3);
|
||||
assert.equal(size.height, 9);
|
||||
assert.equal(size.width, 9);
|
||||
}
|
||||
|
||||
// Transpose
|
||||
{
|
||||
let mat1 = cv.Mat.eye(9, 9, cv.CV_8UC3);
|
||||
let mat2 = new cv.Mat();
|
||||
|
||||
cv.transpose(mat1, mat2);
|
||||
|
||||
// Verify result.
|
||||
let size = mat2.size();
|
||||
assert.equal(mat2.channels(), 3);
|
||||
assert.equal(size.height, 9);
|
||||
assert.equal(size.width, 9);
|
||||
}
|
||||
|
||||
// bilateralFilter
|
||||
{
|
||||
let mat1 = cv.Mat.ones(11, 11, cv.CV_8UC3);
|
||||
let mat2 = new cv.Mat();
|
||||
|
||||
cv.bilateralFilter(mat1, mat2, 3, 6, 1.5, cv.BORDER_DEFAULT);
|
||||
|
||||
// Verify result.
|
||||
let size = mat2.size();
|
||||
assert.equal(mat2.channels(), 3);
|
||||
assert.equal(size.height, 11);
|
||||
assert.equal(size.width, 11);
|
||||
|
||||
// default parameters
|
||||
cv.bilateralFilter(mat1, mat2, 3, 6, 1.5);
|
||||
// Verify result.
|
||||
size = mat2.size();
|
||||
assert.equal(mat2.channels(), 3);
|
||||
assert.equal(size.height, 11);
|
||||
assert.equal(size.width, 11);
|
||||
|
||||
mat1.delete();
|
||||
mat2.delete();
|
||||
}
|
||||
|
||||
// Watershed
|
||||
{
|
||||
let mat = cv.Mat.ones(11, 11, cv.CV_8UC3);
|
||||
let out = new cv.Mat(11, 11, cv.CV_32SC1);
|
||||
|
||||
cv.watershed(mat, out);
|
||||
|
||||
// Verify result.
|
||||
let size = out.size();
|
||||
assert.equal(out.channels(), 1);
|
||||
assert.equal(size.height, 11);
|
||||
assert.equal(size.width, 11);
|
||||
assert.equal(out.elemSize1(), 4);
|
||||
|
||||
mat.delete();
|
||||
out.delete();
|
||||
}
|
||||
|
||||
// Concat
|
||||
{
|
||||
let mat = cv.Mat.ones({height: 10, width: 5}, cv.CV_8UC3);
|
||||
let mat2 = cv.Mat.eye({height: 10, width: 5}, cv.CV_8UC3);
|
||||
let mat3 = cv.Mat.eye({height: 10, width: 5}, cv.CV_8UC3);
|
||||
|
||||
|
||||
let out = new cv.Mat();
|
||||
let input = new cv.MatVector();
|
||||
input.push_back(mat);
|
||||
input.push_back(mat2);
|
||||
input.push_back(mat3);
|
||||
|
||||
cv.vconcat(input, out);
|
||||
|
||||
// Verify result.
|
||||
let size = out.size();
|
||||
assert.equal(out.channels(), 3);
|
||||
assert.equal(size.height, 30);
|
||||
assert.equal(size.width, 5);
|
||||
assert.equal(out.elemSize1(), 1);
|
||||
|
||||
cv.hconcat(input, out);
|
||||
|
||||
// Verify result.
|
||||
size = out.size();
|
||||
assert.equal(out.channels(), 3);
|
||||
assert.equal(size.height, 10);
|
||||
assert.equal(size.width, 15);
|
||||
assert.equal(out.elemSize1(), 1);
|
||||
|
||||
input.delete();
|
||||
out.delete();
|
||||
}
|
||||
|
||||
|
||||
// distanceTransform letiants
|
||||
{
|
||||
let mat = cv.Mat.ones(11, 11, cv.CV_8UC1);
|
||||
let out = new cv.Mat(11, 11, cv.CV_32FC1);
|
||||
let labels = new cv.Mat(11, 11, cv.CV_32FC1);
|
||||
const maskSize = 3;
|
||||
cv.distanceTransform(mat, out, cv.DIST_L2, maskSize, cv.CV_32F);
|
||||
|
||||
// Verify result.
|
||||
let size = out.size();
|
||||
assert.equal(out.channels(), 1);
|
||||
assert.equal(size.height, 11);
|
||||
assert.equal(size.width, 11);
|
||||
assert.equal(out.elemSize1(), 4);
|
||||
|
||||
|
||||
cv.distanceTransformWithLabels(mat, out, labels, cv.DIST_L2, maskSize,
|
||||
cv.DIST_LABEL_CCOMP);
|
||||
|
||||
// Verify result.
|
||||
size = out.size();
|
||||
assert.equal(out.channels(), 1);
|
||||
assert.equal(size.height, 11);
|
||||
assert.equal(size.width, 11);
|
||||
assert.equal(out.elemSize1(), 4);
|
||||
|
||||
size = labels.size();
|
||||
assert.equal(labels.channels(), 1);
|
||||
assert.equal(size.height, 11);
|
||||
assert.equal(size.width, 11);
|
||||
assert.equal(labels.elemSize1(), 4);
|
||||
|
||||
mat.delete();
|
||||
out.delete();
|
||||
labels.delete();
|
||||
}
|
||||
|
||||
// Min, Max
|
||||
{
|
||||
let data1 = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9]);
|
||||
let data2 = new Uint8Array([0, 4, 0, 8, 0, 12, 0, 16, 0]);
|
||||
|
||||
let expectedMin = new Uint8Array([0, 2, 0, 4, 0, 6, 0, 8, 0]);
|
||||
let expectedMax = new Uint8Array([1, 4, 3, 8, 5, 12, 7, 16, 9]);
|
||||
|
||||
let dataPtr = cv._malloc(3*3*1);
|
||||
let dataPtr2 = cv._malloc(3*3*1);
|
||||
|
||||
let dataHeap = new Uint8Array(cv.HEAPU8.buffer, dataPtr, 3*3*1);
|
||||
dataHeap.set(new Uint8Array(data1.buffer));
|
||||
|
||||
let dataHeap2 = new Uint8Array(cv.HEAPU8.buffer, dataPtr2, 3*3*1);
|
||||
dataHeap2.set(new Uint8Array(data2.buffer));
|
||||
|
||||
|
||||
let mat1 = new cv.Mat(3, 3, cv.CV_8UC1, dataPtr, 0);
|
||||
let mat2 = new cv.Mat(3, 3, cv.CV_8UC1, dataPtr2, 0);
|
||||
|
||||
let mat3 = new cv.Mat();
|
||||
|
||||
cv.min(mat1, mat2, mat3);
|
||||
// Verify result.
|
||||
let size = mat2.size();
|
||||
assert.equal(mat2.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(mat3.data, expectedMin);
|
||||
|
||||
|
||||
cv.max(mat1, mat2, mat3);
|
||||
// Verify result.
|
||||
size = mat2.size();
|
||||
assert.equal(mat2.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(mat3.data, expectedMax);
|
||||
|
||||
cv._free(dataPtr);
|
||||
cv._free(dataPtr2);
|
||||
}
|
||||
|
||||
// Bitwise operations
|
||||
{
|
||||
let data1 = new Uint8Array([0, 1, 2, 4, 8, 16, 32, 64, 128]);
|
||||
let data2 = new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255, 255]);
|
||||
|
||||
let expectedAnd = new Uint8Array([0, 1, 2, 4, 8, 16, 32, 64, 128]);
|
||||
let expectedOr = new Uint8Array([255, 255, 255, 255, 255, 255, 255, 255, 255]);
|
||||
let expectedXor = new Uint8Array([255, 254, 253, 251, 247, 239, 223, 191, 127]);
|
||||
|
||||
let expectedNot = new Uint8Array([255, 254, 253, 251, 247, 239, 223, 191, 127]);
|
||||
|
||||
let dataPtr = cv._malloc(3*3*1);
|
||||
let dataPtr2 = cv._malloc(3*3*1);
|
||||
|
||||
let dataHeap = new Uint8Array(cv.HEAPU8.buffer, dataPtr, 3*3*1);
|
||||
dataHeap.set(new Uint8Array(data1.buffer));
|
||||
|
||||
let dataHeap2 = new Uint8Array(cv.HEAPU8.buffer, dataPtr2, 3*3*1);
|
||||
dataHeap2.set(new Uint8Array(data2.buffer));
|
||||
|
||||
|
||||
let mat1 = new cv.Mat(3, 3, cv.CV_8UC1, dataPtr, 0);
|
||||
let mat2 = new cv.Mat(3, 3, cv.CV_8UC1, dataPtr2, 0);
|
||||
|
||||
let mat3 = new cv.Mat();
|
||||
let none = new cv.Mat();
|
||||
|
||||
cv.bitwise_not(mat1, mat3, none);
|
||||
// Verify result.
|
||||
let size = mat3.size();
|
||||
assert.equal(mat3.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(mat3.data, expectedNot);
|
||||
|
||||
cv.bitwise_and(mat1, mat2, mat3, none);
|
||||
// Verify result.
|
||||
size = mat3.size();
|
||||
assert.equal(mat3.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(mat3.data, expectedAnd);
|
||||
|
||||
|
||||
cv.bitwise_or(mat1, mat2, mat3, none);
|
||||
// Verify result.
|
||||
size = mat3.size();
|
||||
assert.equal(mat3.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(mat3.data, expectedOr);
|
||||
|
||||
cv.bitwise_xor(mat1, mat2, mat3, none);
|
||||
// Verify result.
|
||||
size = mat3.size();
|
||||
assert.equal(mat3.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(mat3.data, expectedXor);
|
||||
|
||||
cv._free(dataPtr);
|
||||
cv._free(dataPtr2);
|
||||
}
|
||||
|
||||
// Arithmetic operations
|
||||
{
|
||||
let data1 = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
let data2 = new Uint8Array([0, 2, 4, 6, 8, 10, 12, 14, 16]);
|
||||
let data3 = new Uint8Array([0, 1, 0, 1, 0, 1, 0, 1, 0]);
|
||||
|
||||
// |data1 - data2|
|
||||
let expectedAbsDiff = new Uint8Array([0, 1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
let expectedAdd = new Uint8Array([0, 3, 6, 9, 12, 15, 18, 21, 24]);
|
||||
|
||||
const alpha = 4;
|
||||
const beta = -1;
|
||||
const gamma = 3;
|
||||
// 4*data1 - data2 + 3
|
||||
let expectedWeightedAdd = new Uint8Array([3, 5, 7, 9, 11, 13, 15, 17, 19]);
|
||||
|
||||
let dataPtr = cv._malloc(3*3*1);
|
||||
let dataPtr2 = cv._malloc(3*3*1);
|
||||
let dataPtr3 = cv._malloc(3*3*1);
|
||||
|
||||
let dataHeap = new Uint8Array(cv.HEAPU8.buffer, dataPtr, 3*3*1);
|
||||
dataHeap.set(new Uint8Array(data1.buffer));
|
||||
let dataHeap2 = new Uint8Array(cv.HEAPU8.buffer, dataPtr2, 3*3*1);
|
||||
dataHeap2.set(new Uint8Array(data2.buffer));
|
||||
let dataHeap3 = new Uint8Array(cv.HEAPU8.buffer, dataPtr3, 3*3*1);
|
||||
dataHeap3.set(new Uint8Array(data3.buffer));
|
||||
|
||||
let mat1 = new cv.Mat(3, 3, cv.CV_8UC1, dataPtr, 0);
|
||||
let mat2 = new cv.Mat(3, 3, cv.CV_8UC1, dataPtr2, 0);
|
||||
let mat3 = new cv.Mat(3, 3, cv.CV_8UC1, dataPtr3, 0);
|
||||
|
||||
let dst = new cv.Mat();
|
||||
let none = new cv.Mat();
|
||||
|
||||
cv.absdiff(mat1, mat2, dst);
|
||||
// Verify result.
|
||||
let size = dst.size();
|
||||
assert.equal(dst.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(dst.data, expectedAbsDiff);
|
||||
|
||||
cv.add(mat1, mat2, dst, none, -1);
|
||||
// Verify result.
|
||||
size = dst.size();
|
||||
assert.equal(dst.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(dst.data, expectedAdd);
|
||||
|
||||
cv.addWeighted(mat1, alpha, mat2, beta, gamma, dst, -1);
|
||||
// Verify result.
|
||||
size = dst.size();
|
||||
assert.equal(dst.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(dst.data, expectedWeightedAdd);
|
||||
|
||||
// default parameter
|
||||
cv.addWeighted(mat1, alpha, mat2, beta, gamma, dst);
|
||||
// Verify result.
|
||||
size = dst.size();
|
||||
assert.equal(dst.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
|
||||
assert.deepEqual(dst.data, expectedWeightedAdd);
|
||||
|
||||
mat1.delete();
|
||||
mat2.delete();
|
||||
mat3.delete();
|
||||
dst.delete();
|
||||
none.delete();
|
||||
}
|
||||
|
||||
// Integral letiants
|
||||
{
|
||||
let mat = cv.Mat.eye({height: 100, width: 100}, cv.CV_8UC3);
|
||||
let sum = new cv.Mat();
|
||||
let sqSum = new cv.Mat();
|
||||
let title = new cv.Mat();
|
||||
|
||||
cv.integral(mat, sum, -1);
|
||||
|
||||
// Verify result.
|
||||
let size = sum.size();
|
||||
assert.equal(sum.channels(), 3);
|
||||
assert.equal(size.height, 100+1);
|
||||
assert.equal(size.width, 100+1);
|
||||
|
||||
cv.integral2(mat, sum, sqSum, -1, -1);
|
||||
// Verify result.
|
||||
size = sum.size();
|
||||
assert.equal(sum.channels(), 3);
|
||||
assert.equal(size.height, 100+1);
|
||||
assert.equal(size.width, 100+1);
|
||||
|
||||
size = sqSum.size();
|
||||
assert.equal(sqSum.channels(), 3);
|
||||
assert.equal(size.height, 100+1);
|
||||
assert.equal(size.width, 100+1);
|
||||
|
||||
mat.delete();
|
||||
sum.delete();
|
||||
sqSum.delete();
|
||||
title.delete();
|
||||
}
|
||||
|
||||
// Mean, meanSTDev
|
||||
{
|
||||
let mat = cv.Mat.eye({height: 100, width: 100}, cv.CV_8UC3);
|
||||
let sum = new cv.Mat();
|
||||
let sqSum = new cv.Mat();
|
||||
let title = new cv.Mat();
|
||||
|
||||
cv.integral(mat, sum, -1);
|
||||
|
||||
// Verify result.
|
||||
let size = sum.size();
|
||||
assert.equal(sum.channels(), 3);
|
||||
assert.equal(size.height, 100+1);
|
||||
assert.equal(size.width, 100+1);
|
||||
|
||||
cv.integral2(mat, sum, sqSum, -1, -1);
|
||||
// Verify result.
|
||||
size = sum.size();
|
||||
assert.equal(sum.channels(), 3);
|
||||
assert.equal(size.height, 100+1);
|
||||
assert.equal(size.width, 100+1);
|
||||
|
||||
size = sqSum.size();
|
||||
assert.equal(sqSum.channels(), 3);
|
||||
assert.equal(size.height, 100+1);
|
||||
assert.equal(size.width, 100+1);
|
||||
|
||||
mat.delete();
|
||||
sum.delete();
|
||||
sqSum.delete();
|
||||
title.delete();
|
||||
}
|
||||
|
||||
// Invert
|
||||
{
|
||||
let inv1 = new cv.Mat();
|
||||
let inv2 = new cv.Mat();
|
||||
let inv3 = new cv.Mat();
|
||||
let inv4 = new cv.Mat();
|
||||
|
||||
|
||||
let data1 = new Float32Array([1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1]);
|
||||
let data2 = new Float32Array([0, 0, 0,
|
||||
0, 5, 0,
|
||||
0, 0, 0]);
|
||||
let data3 = new Float32Array([1, 1, 1, 0,
|
||||
0, 3, 1, 2,
|
||||
2, 3, 1, 0,
|
||||
1, 0, 2, 1]);
|
||||
let data4 = new Float32Array([1, 4, 5,
|
||||
4, 2, 2,
|
||||
5, 2, 2]);
|
||||
|
||||
let expected1 = new Float32Array([1, 0, 0,
|
||||
0, 1, 0,
|
||||
0, 0, 1]);
|
||||
// Inverse does not exist!
|
||||
let expected3 = new Float32Array([-3, -1/2, 3/2, 1,
|
||||
1, 1/4, -1/4, -1/2,
|
||||
3, 1/4, -5/4, -1/2,
|
||||
-3, 0, 1, 1]);
|
||||
let expected4 = new Float32Array([0, -1, 1,
|
||||
-1, 23/2, -9,
|
||||
1, -9, 7]);
|
||||
|
||||
let dataPtr1 = cv._malloc(3*3*4);
|
||||
let dataPtr2 = cv._malloc(3*3*4);
|
||||
let dataPtr3 = cv._malloc(4*4*4);
|
||||
let dataPtr4 = cv._malloc(3*3*4);
|
||||
|
||||
let dataHeap = new Float32Array(cv.HEAP32.buffer, dataPtr1, 3*3);
|
||||
dataHeap.set(new Float32Array(data1.buffer));
|
||||
let dataHeap2 = new Float32Array(cv.HEAP32.buffer, dataPtr2, 3*3);
|
||||
dataHeap2.set(new Float32Array(data2.buffer));
|
||||
let dataHeap3 = new Float32Array(cv.HEAP32.buffer, dataPtr3, 4*4);
|
||||
dataHeap3.set(new Float32Array(data3.buffer));
|
||||
let dataHeap4 = new Float32Array(cv.HEAP32.buffer, dataPtr4, 3*3);
|
||||
dataHeap4.set(new Float32Array(data4.buffer));
|
||||
|
||||
let mat1 = new cv.Mat(3, 3, cv.CV_32FC1, dataPtr1, 0);
|
||||
let mat2 = new cv.Mat(3, 3, cv.CV_32FC1, dataPtr2, 0);
|
||||
let mat3 = new cv.Mat(4, 4, cv.CV_32FC1, dataPtr3, 0);
|
||||
let mat4 = new cv.Mat(3, 3, cv.CV_32FC1, dataPtr4, 0);
|
||||
|
||||
QUnit.assert.deepEqualWithTolerance = function( value, expected, tolerance ) {
|
||||
for (let i = 0; i < value.length; i= i+1) {
|
||||
this.pushResult( {
|
||||
result: Math.abs(value[i]-expected[i]) < tolerance,
|
||||
actual: value[i],
|
||||
expected: expected[i],
|
||||
} );
|
||||
}
|
||||
};
|
||||
|
||||
cv.invert(mat1, inv1, 0);
|
||||
// Verify result.
|
||||
let size = inv1.size();
|
||||
assert.equal(inv1.channels(), 1);
|
||||
assert.equal(size.height, 3);
|
||||
assert.equal(size.width, 3);
|
||||
assert.deepEqualWithTolerance(inv1.data32F, expected1, 0.0001);
|
||||
|
||||
|
||||
cv.invert(mat2, inv2, 0);
|
||||
// Verify result.
|
||||
assert.deepEqualWithTolerance(inv3.data32F, expected3, 0.0001);
|
||||
|
||||
cv.invert(mat3, inv3, 0);
|
||||
// Verify result.
|
||||
size = inv3.size();
|
||||
assert.equal(inv3.channels(), 1);
|
||||
assert.equal(size.height, 4);
|
||||
assert.equal(size.width, 4);
|
||||
assert.deepEqualWithTolerance(inv3.data32F, expected3, 0.0001);
|
||||
|
||||
cv.invert(mat3, inv3, 1);
|
||||
// Verify result.
|
||||
assert.deepEqualWithTolerance(inv3.data32F, expected3, 0.0001);
|
||||
|
||||
cv.invert(mat4, inv4, 2);
|
||||
// Verify result.
|
||||
assert.deepEqualWithTolerance(inv4.data32F, expected4, 0.0001);
|
||||
|
||||
cv.invert(mat4, inv4, 3);
|
||||
// Verify result.
|
||||
assert.deepEqualWithTolerance(inv4.data32F, expected4, 0.0001);
|
||||
|
||||
mat1.delete();
|
||||
mat2.delete();
|
||||
mat3.delete();
|
||||
mat4.delete();
|
||||
inv1.delete();
|
||||
inv2.delete();
|
||||
inv3.delete();
|
||||
inv4.delete();
|
||||
}
|
||||
//Rotate
|
||||
{
|
||||
let dst = new cv.Mat();
|
||||
let src = cv.matFromArray(3, 2, cv.CV_8U, [1,2,3,4,5,6]);
|
||||
|
||||
cv.rotate(src, dst, cv.ROTATE_90_CLOCKWISE);
|
||||
|
||||
size = dst.size();
|
||||
assert.equal(size.height, 2, "ROTATE_HEIGHT");
|
||||
assert.equal(size.width, 3, "ROTATE_WIGTH");
|
||||
|
||||
let expected = new Uint8Array([5,3,1,6,4,2]);
|
||||
|
||||
assert.deepEqual(dst.data, expected);
|
||||
|
||||
dst.delete();
|
||||
src.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('warpPolar', function(assert) {
|
||||
const lines = new cv.Mat(255, 255, cv.CV_8U, new cv.Scalar(0));
|
||||
for (let r = 0; r < lines.rows; r++) {
|
||||
lines.row(r).setTo(new cv.Scalar(r));
|
||||
}
|
||||
cv.warpPolar(lines, lines, { width: 5, height: 5 }, new cv.Point(2, 2), 3,
|
||||
cv.INTER_CUBIC | cv.WARP_FILL_OUTLIERS | cv.WARP_INVERSE_MAP);
|
||||
assert.ok(lines instanceof cv.Mat);
|
||||
assert.deepEqual(Array.from(lines.data), [
|
||||
159, 172, 191, 210, 223,
|
||||
146, 159, 191, 223, 236,
|
||||
128, 128, 0, 0, 0,
|
||||
109, 96, 64, 32, 19,
|
||||
96, 83, 64, 45, 32
|
||||
]);
|
||||
});
|
||||
987
Lib/opencv/sources/modules/js/test/test_mat.js
Normal file
987
Lib/opencv/sources/modules/js/test/test_mat.js
Normal file
@@ -0,0 +1,987 @@
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
// Author: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
|
||||
//
|
||||
// LICENSE AGREEMENT
|
||||
// Copyright (c) 2015 The Regents of the University of California (Regents)
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the University nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
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_mat_creation', function(assert) {
|
||||
// Mat constructors.
|
||||
// Mat::Mat(int rows, int cols, int type)
|
||||
{
|
||||
let mat = new cv.Mat(10, 20, cv.CV_8UC3);
|
||||
|
||||
assert.equal(mat.type(), cv.CV_8UC3);
|
||||
assert.equal(mat.depth(), cv.CV_8U);
|
||||
assert.equal(mat.channels(), 3);
|
||||
assert.ok(mat.empty() === false);
|
||||
|
||||
let size = mat.size();
|
||||
assert.equal(size.height, 10);
|
||||
assert.equal(size.width, 20);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// Mat::Mat(const Mat &)
|
||||
{
|
||||
// Copy from another Mat
|
||||
let mat1 = new cv.Mat(10, 20, cv.CV_8UC3);
|
||||
let mat2 = new cv.Mat(mat1);
|
||||
|
||||
assert.equal(mat2.type(), mat1.type());
|
||||
assert.equal(mat2.depth(), mat1.depth());
|
||||
assert.equal(mat2.channels(), mat1.channels());
|
||||
assert.equal(mat2.empty(), mat1.empty());
|
||||
|
||||
let size1 = mat1.size;
|
||||
let size2 = mat2.size();
|
||||
assert.ok(size1[0] === size2[0]);
|
||||
assert.ok(size1[1] === size2[1]);
|
||||
|
||||
mat1.delete();
|
||||
mat2.delete();
|
||||
}
|
||||
|
||||
// Mat::Mat(int rows, int cols, int type, void *data, size_t step=AUTO_STEP)
|
||||
{
|
||||
// 10 * 10 and one channel
|
||||
let data = cv._malloc(10 * 10 * 1);
|
||||
let mat = new cv.Mat(10, 10, cv.CV_8UC1, data, 0);
|
||||
|
||||
assert.equal(mat.type(), cv.CV_8UC1);
|
||||
assert.equal(mat.depth(), cv.CV_8U);
|
||||
assert.equal(mat.channels(), 1);
|
||||
assert.ok(mat.empty() === false);
|
||||
|
||||
let size = mat.size();
|
||||
assert.ok(size.height === 10);
|
||||
assert.ok(size.width === 10);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// Mat::Mat(int rows, int cols, int type, const Scalar& scalar)
|
||||
{
|
||||
// 2 * 2 8UC4 mat
|
||||
let mat = new cv.Mat(2, 2, cv.CV_8UC4, [0, 1, 2, 3]);
|
||||
|
||||
for (let r = 0; r < mat.rows; r++) {
|
||||
for (let c = 0; c < mat.cols; c++) {
|
||||
let element = mat.ptr(r, c);
|
||||
assert.equal(element[0], 0);
|
||||
assert.equal(element[1], 1);
|
||||
assert.equal(element[2], 2);
|
||||
assert.equal(element[3], 3);
|
||||
}
|
||||
}
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// Mat::create(int, int, int)
|
||||
{
|
||||
let mat = new cv.Mat();
|
||||
mat.create(10, 5, cv.CV_8UC3);
|
||||
let size = mat.size();
|
||||
|
||||
assert.ok(mat.type() === cv.CV_8UC3);
|
||||
assert.ok(size.height === 10);
|
||||
assert.ok(size.width === 5);
|
||||
assert.ok(mat.channels() === 3);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
// Mat::create(Size, int)
|
||||
{
|
||||
let mat = new cv.Mat();
|
||||
mat.create({height: 10, width: 5}, cv.CV_8UC4);
|
||||
let size = mat.size();
|
||||
|
||||
assert.ok(mat.type() === cv.CV_8UC4);
|
||||
assert.ok(size.height === 10);
|
||||
assert.ok(size.width === 5);
|
||||
assert.ok(mat.channels() === 4);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
// clone
|
||||
{
|
||||
let mat = cv.Mat.ones(5, 5, cv.CV_8UC1);
|
||||
let mat2 = mat.clone();
|
||||
|
||||
assert.equal(mat.channels, mat2.channels);
|
||||
assert.equal(mat.size().height, mat2.size().height);
|
||||
assert.equal(mat.size().width, mat2.size().width);
|
||||
|
||||
assert.deepEqual(mat.data, mat2.data);
|
||||
|
||||
|
||||
mat.delete();
|
||||
mat2.delete();
|
||||
}
|
||||
// copyTo
|
||||
{
|
||||
let mat = cv.Mat.ones(5, 5, cv.CV_8UC1);
|
||||
let mat2 = new cv.Mat();
|
||||
mat.copyTo(mat2);
|
||||
|
||||
assert.equal(mat.channels, mat2.channels);
|
||||
assert.equal(mat.size().height, mat2.size().height);
|
||||
assert.equal(mat.size().width, mat2.size().width);
|
||||
|
||||
assert.deepEqual(mat.data, mat2.data);
|
||||
|
||||
|
||||
mat.delete();
|
||||
mat2.delete();
|
||||
}
|
||||
// copyTo1
|
||||
{
|
||||
let mat = cv.Mat.ones(5, 5, cv.CV_8UC1);
|
||||
let mat2 = new cv.Mat();
|
||||
let mask = new cv.Mat(5, 5, cv.CV_8UC1, new cv.Scalar(1));
|
||||
mat.copyTo(mat2, mask);
|
||||
|
||||
assert.equal(mat.channels, mat2.channels);
|
||||
assert.equal(mat.size().height, mat2.size().height);
|
||||
assert.equal(mat.size().width, mat2.size().width);
|
||||
|
||||
assert.deepEqual(mat.data, mat2.data);
|
||||
|
||||
|
||||
mat.delete();
|
||||
mat2.delete();
|
||||
mask.delete();
|
||||
}
|
||||
|
||||
// matFromArray
|
||||
{
|
||||
let arrayC1 = [0, -1, 2, -3];
|
||||
let arrayC2 = [0, -1, 2, -3, 4, -5, 6, -7];
|
||||
let arrayC3 = [0, -1, 2, -3, 4, -5, 6, -7, 9, -9, 10, -11];
|
||||
let arrayC4 = [0, -1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, 13, 14, 15];
|
||||
|
||||
let mat8UC1 = cv.matFromArray(2, 2, cv.CV_8UC1, arrayC1);
|
||||
let mat8UC2 = cv.matFromArray(2, 2, cv.CV_8UC2, arrayC2);
|
||||
let mat8UC3 = cv.matFromArray(2, 2, cv.CV_8UC3, arrayC3);
|
||||
let mat8UC4 = cv.matFromArray(2, 2, cv.CV_8UC4, arrayC4);
|
||||
|
||||
let mat8SC1 = cv.matFromArray(2, 2, cv.CV_8SC1, arrayC1);
|
||||
let mat8SC2 = cv.matFromArray(2, 2, cv.CV_8SC2, arrayC2);
|
||||
let mat8SC3 = cv.matFromArray(2, 2, cv.CV_8SC3, arrayC3);
|
||||
let mat8SC4 = cv.matFromArray(2, 2, cv.CV_8SC4, arrayC4);
|
||||
|
||||
let mat16UC1 = cv.matFromArray(2, 2, cv.CV_16UC1, arrayC1);
|
||||
let mat16UC2 = cv.matFromArray(2, 2, cv.CV_16UC2, arrayC2);
|
||||
let mat16UC3 = cv.matFromArray(2, 2, cv.CV_16UC3, arrayC3);
|
||||
let mat16UC4 = cv.matFromArray(2, 2, cv.CV_16UC4, arrayC4);
|
||||
|
||||
let mat16SC1 = cv.matFromArray(2, 2, cv.CV_16SC1, arrayC1);
|
||||
let mat16SC2 = cv.matFromArray(2, 2, cv.CV_16SC2, arrayC2);
|
||||
let mat16SC3 = cv.matFromArray(2, 2, cv.CV_16SC3, arrayC3);
|
||||
let mat16SC4 = cv.matFromArray(2, 2, cv.CV_16SC4, arrayC4);
|
||||
|
||||
let mat32SC1 = cv.matFromArray(2, 2, cv.CV_32SC1, arrayC1);
|
||||
let mat32SC2 = cv.matFromArray(2, 2, cv.CV_32SC2, arrayC2);
|
||||
let mat32SC3 = cv.matFromArray(2, 2, cv.CV_32SC3, arrayC3);
|
||||
let mat32SC4 = cv.matFromArray(2, 2, cv.CV_32SC4, arrayC4);
|
||||
|
||||
let mat32FC1 = cv.matFromArray(2, 2, cv.CV_32FC1, arrayC1);
|
||||
let mat32FC2 = cv.matFromArray(2, 2, cv.CV_32FC2, arrayC2);
|
||||
let mat32FC3 = cv.matFromArray(2, 2, cv.CV_32FC3, arrayC3);
|
||||
let mat32FC4 = cv.matFromArray(2, 2, cv.CV_32FC4, arrayC4);
|
||||
|
||||
let mat64FC1 = cv.matFromArray(2, 2, cv.CV_64FC1, arrayC1);
|
||||
let mat64FC2 = cv.matFromArray(2, 2, cv.CV_64FC2, arrayC2);
|
||||
let mat64FC3 = cv.matFromArray(2, 2, cv.CV_64FC3, arrayC3);
|
||||
let mat64FC4 = cv.matFromArray(2, 2, cv.CV_64FC4, arrayC4);
|
||||
|
||||
assert.deepEqual(mat8UC1.data, new Uint8Array(arrayC1));
|
||||
assert.deepEqual(mat8UC2.data, new Uint8Array(arrayC2));
|
||||
assert.deepEqual(mat8UC3.data, new Uint8Array(arrayC3));
|
||||
assert.deepEqual(mat8UC4.data, new Uint8Array(arrayC4));
|
||||
|
||||
assert.deepEqual(mat8SC1.data8S, new Int8Array(arrayC1));
|
||||
assert.deepEqual(mat8SC2.data8S, new Int8Array(arrayC2));
|
||||
assert.deepEqual(mat8SC3.data8S, new Int8Array(arrayC3));
|
||||
assert.deepEqual(mat8SC4.data8S, new Int8Array(arrayC4));
|
||||
|
||||
assert.deepEqual(mat16UC1.data16U, new Uint16Array(arrayC1));
|
||||
assert.deepEqual(mat16UC2.data16U, new Uint16Array(arrayC2));
|
||||
assert.deepEqual(mat16UC3.data16U, new Uint16Array(arrayC3));
|
||||
assert.deepEqual(mat16UC4.data16U, new Uint16Array(arrayC4));
|
||||
|
||||
assert.deepEqual(mat16SC1.data16S, new Int16Array(arrayC1));
|
||||
assert.deepEqual(mat16SC2.data16S, new Int16Array(arrayC2));
|
||||
assert.deepEqual(mat16SC3.data16S, new Int16Array(arrayC3));
|
||||
assert.deepEqual(mat16SC4.data16S, new Int16Array(arrayC4));
|
||||
|
||||
assert.deepEqual(mat32SC1.data32S, new Int32Array(arrayC1));
|
||||
assert.deepEqual(mat32SC2.data32S, new Int32Array(arrayC2));
|
||||
assert.deepEqual(mat32SC3.data32S, new Int32Array(arrayC3));
|
||||
assert.deepEqual(mat32SC4.data32S, new Int32Array(arrayC4));
|
||||
|
||||
assert.deepEqual(mat32FC1.data32F, new Float32Array(arrayC1));
|
||||
assert.deepEqual(mat32FC2.data32F, new Float32Array(arrayC2));
|
||||
assert.deepEqual(mat32FC3.data32F, new Float32Array(arrayC3));
|
||||
assert.deepEqual(mat32FC4.data32F, new Float32Array(arrayC4));
|
||||
|
||||
assert.deepEqual(mat64FC1.data64F, new Float64Array(arrayC1));
|
||||
assert.deepEqual(mat64FC2.data64F, new Float64Array(arrayC2));
|
||||
assert.deepEqual(mat64FC3.data64F, new Float64Array(arrayC3));
|
||||
assert.deepEqual(mat64FC4.data64F, new Float64Array(arrayC4));
|
||||
|
||||
mat8UC1.delete();
|
||||
mat8UC2.delete();
|
||||
mat8UC3.delete();
|
||||
mat8UC4.delete();
|
||||
mat8SC1.delete();
|
||||
mat8SC2.delete();
|
||||
mat8SC3.delete();
|
||||
mat8SC4.delete();
|
||||
mat16UC1.delete();
|
||||
mat16UC2.delete();
|
||||
mat16UC3.delete();
|
||||
mat16UC4.delete();
|
||||
mat16SC1.delete();
|
||||
mat16SC2.delete();
|
||||
mat16SC3.delete();
|
||||
mat16SC4.delete();
|
||||
mat32SC1.delete();
|
||||
mat32SC2.delete();
|
||||
mat32SC3.delete();
|
||||
mat32SC4.delete();
|
||||
mat32FC1.delete();
|
||||
mat32FC2.delete();
|
||||
mat32FC3.delete();
|
||||
mat32FC4.delete();
|
||||
mat64FC1.delete();
|
||||
mat64FC2.delete();
|
||||
mat64FC3.delete();
|
||||
mat64FC4.delete();
|
||||
}
|
||||
|
||||
// matFromImageData
|
||||
{
|
||||
// Only test in browser
|
||||
if (typeof window === 'undefined') {
|
||||
return;
|
||||
}
|
||||
let canvas = window.document.createElement('canvas');
|
||||
canvas.width = 2;
|
||||
canvas.height = 2;
|
||||
let ctx = canvas.getContext('2d');
|
||||
ctx.fillStyle='#FF0000';
|
||||
ctx.fillRect(0, 0, 1, 1);
|
||||
ctx.fillRect(1, 1, 1, 1);
|
||||
|
||||
let imageData = ctx.getImageData(0, 0, 2, 2);
|
||||
let mat = cv.matFromImageData(imageData);
|
||||
|
||||
assert.deepEqual(mat.data, new Uint8Array(imageData.data));
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// Mat(mat)
|
||||
{
|
||||
let mat = new cv.Mat(2, 2, cv.CV_8UC4, new cv.Scalar(1, 0, 1, 0));
|
||||
let mat1 = new cv.Mat(mat);
|
||||
let mat2 = mat;
|
||||
|
||||
assert.equal(mat.rows, mat1.rows);
|
||||
assert.equal(mat.cols, mat1.cols);
|
||||
assert.equal(mat.type(), mat1.type());
|
||||
assert.deepEqual(mat.data, mat1.data);
|
||||
|
||||
mat.delete();
|
||||
|
||||
assert.equal(mat1.isDeleted(), false);
|
||||
assert.equal(mat2.isDeleted(), true);
|
||||
|
||||
mat1.delete();
|
||||
}
|
||||
|
||||
// mat.setTo
|
||||
{
|
||||
let mat = new cv.Mat(2, 2, cv.CV_8UC4);
|
||||
let s = [0, 1, 2, 3];
|
||||
|
||||
mat.setTo(s);
|
||||
|
||||
assert.deepEqual(mat.ptr(0, 0), new Uint8Array(s));
|
||||
assert.deepEqual(mat.ptr(0, 1), new Uint8Array(s));
|
||||
assert.deepEqual(mat.ptr(1, 0), new Uint8Array(s));
|
||||
assert.deepEqual(mat.ptr(1, 1), new Uint8Array(s));
|
||||
|
||||
let s1 = [0, 0, 0, 0];
|
||||
mat.setTo(s1);
|
||||
let mask = cv.matFromArray(2, 2, cv.CV_8UC1, [0, 1, 0, 1]);
|
||||
mat.setTo(s, mask);
|
||||
|
||||
assert.deepEqual(mat.ptr(0, 0), new Uint8Array(s1));
|
||||
assert.deepEqual(mat.ptr(0, 1), new Uint8Array(s));
|
||||
assert.deepEqual(mat.ptr(1, 0), new Uint8Array(s1));
|
||||
assert.deepEqual(mat.ptr(1, 1), new Uint8Array(s));
|
||||
|
||||
mat.delete();
|
||||
mask.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_mat_ptr', function(assert) {
|
||||
const RValue = 3;
|
||||
const GValue = 7;
|
||||
const BValue = 197;
|
||||
|
||||
// cv.CV_8UC1 + Mat::ptr(int).
|
||||
{
|
||||
let mat = new cv.Mat(10, 10, cv.CV_8UC1);
|
||||
let view = mat.data;
|
||||
|
||||
// Alter matrix[2, 1].
|
||||
let step = 10;
|
||||
view[2 * step + 1] = RValue;
|
||||
|
||||
// Access matrix[2, 1].
|
||||
view = mat.ptr(2);
|
||||
|
||||
assert.equal(view[1], RValue);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// cv.CV_8UC3 + Mat::ptr(int).
|
||||
{
|
||||
let mat = new cv.Mat(10, 10, cv.CV_8UC3);
|
||||
let view = mat.data;
|
||||
|
||||
// Alter matrix[2, 1].
|
||||
let step = 3 * 10;
|
||||
view[2 * step + 3] = RValue;
|
||||
view[2 * step + 3 + 1] = GValue;
|
||||
view[2 * step + 3 + 2] = BValue;
|
||||
|
||||
// Access matrix[2, 1].
|
||||
view = mat.ptr(2);
|
||||
|
||||
assert.equal(view[3], RValue);
|
||||
assert.equal(view[3 + 1], GValue);
|
||||
assert.equal(view[3 + 2], BValue);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// cv.CV_8UC3 + Mat::ptr(int, int).
|
||||
{
|
||||
let mat = new cv.Mat(10, 10, cv.CV_8UC3);
|
||||
let view = mat.data;
|
||||
|
||||
// Alter matrix[2, 1].
|
||||
let step = 3 * 10;
|
||||
view[2 * step + 3] = RValue;
|
||||
view[2 * step + 3 + 1] = GValue;
|
||||
view[2 * step + 3 + 2] = BValue;
|
||||
|
||||
// Access matrix[2, 1].
|
||||
view = mat.ptr(2, 1);
|
||||
|
||||
assert.equal(view[0], RValue);
|
||||
assert.equal(view[1], GValue);
|
||||
assert.equal(view[2], BValue);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
const RValueF32 = 3.3;
|
||||
const GValueF32 = 7.3;
|
||||
const BValueF32 = 197.3;
|
||||
const EPSILON = 0.001;
|
||||
|
||||
// cv.CV_32FC1 + Mat::ptr(int).
|
||||
{
|
||||
let mat = new cv.Mat(10, 10, cv.CV_32FC1);
|
||||
let view = mat.data32F;
|
||||
|
||||
// Alter matrix[2, 1].
|
||||
let step = 10;
|
||||
view[2 * step + 1] = RValueF32;
|
||||
|
||||
// Access matrix[2, 1].
|
||||
view = mat.floatPtr(2);
|
||||
|
||||
assert.ok(Math.abs(view[1] - RValueF32) < EPSILON);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// cv.CV_32FC3 + Mat::ptr(int).
|
||||
{
|
||||
let mat = new cv.Mat(10, 10, cv.CV_32FC3);
|
||||
let view = mat.data32F;
|
||||
|
||||
// Alter matrix[2, 1].
|
||||
let step = mat.step1(0);
|
||||
view[2 * step + 3] = RValueF32;
|
||||
view[2 * step + 3 + 1] = GValueF32;
|
||||
view[2 * step + 3 + 2] = BValueF32;
|
||||
|
||||
// Access matrix[2, 1].
|
||||
view = mat.floatPtr(2);
|
||||
|
||||
assert.ok(Math.abs(view[3] - RValueF32) < EPSILON);
|
||||
assert.ok(Math.abs(view[3 + 1] - GValueF32) < EPSILON);
|
||||
assert.ok(Math.abs(view[3 + 2] - BValueF32) < EPSILON);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// cv.CV_32FC3 + Mat::ptr(int, int).
|
||||
{
|
||||
let mat = new cv.Mat(10, 10, cv.CV_32FC3);
|
||||
let view = mat.data32F;
|
||||
|
||||
// Alter matrix[2, 1].
|
||||
let step = mat.step1(0);
|
||||
view[2 * step + 3] = RValueF32;
|
||||
view[2 * step + 3 + 1] = GValueF32;
|
||||
view[2 * step + 3 + 2] = BValueF32;
|
||||
|
||||
// Access matrix[2, 1].
|
||||
view = mat.floatPtr(2, 1);
|
||||
|
||||
assert.ok(Math.abs(view[0] - RValueF32) < EPSILON);
|
||||
assert.ok(Math.abs(view[1] - GValueF32) < EPSILON);
|
||||
assert.ok(Math.abs(view[2] - BValueF32) < EPSILON);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_mat_zeros', function(assert) {
|
||||
let zeros = new Uint8Array(10*10).fill(0);
|
||||
// Mat::zeros(int, int, int)
|
||||
{
|
||||
let mat = cv.Mat.zeros(10, 10, cv.CV_8UC1);
|
||||
let view = mat.data;
|
||||
|
||||
assert.deepEqual(view, zeros);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// Mat::zeros(Size, int)
|
||||
{
|
||||
let mat = cv.Mat.zeros({height: 10, width: 10}, cv.CV_8UC1);
|
||||
let view = mat.data;
|
||||
|
||||
assert.deepEqual(view, zeros);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_mat_ones', function(assert) {
|
||||
let ones = new Uint8Array(10*10).fill(1);
|
||||
// Mat::ones(int, int, int)
|
||||
{
|
||||
let mat = cv.Mat.ones(10, 10, cv.CV_8UC1);
|
||||
let view = mat.data;
|
||||
|
||||
assert.deepEqual(view, ones);
|
||||
}
|
||||
// Mat::ones(Size, int)
|
||||
{
|
||||
let mat = cv.Mat.ones({height: 10, width: 10}, cv.CV_8UC1);
|
||||
let view = mat.data;
|
||||
|
||||
assert.deepEqual(view, ones);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_mat_eye', function(assert) {
|
||||
let eye4by4 = new Uint8Array([1, 0, 0, 0,
|
||||
0, 1, 0, 0,
|
||||
0, 0, 1, 0,
|
||||
0, 0, 0, 1]);
|
||||
// Mat::eye(int, int, int)
|
||||
{
|
||||
let mat = cv.Mat.eye(4, 4, cv.CV_8UC1);
|
||||
let view = mat.data;
|
||||
|
||||
assert.deepEqual(view, eye4by4);
|
||||
}
|
||||
|
||||
// Mat::eye(Size, int)
|
||||
{
|
||||
let mat = cv.Mat.eye({height: 4, width: 4}, cv.CV_8UC1);
|
||||
let view = mat.data;
|
||||
|
||||
assert.deepEqual(view, eye4by4);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_mat_miscs', function(assert) {
|
||||
// Mat::col(int)
|
||||
{
|
||||
let mat = cv.matFromArray(2, 2, cv.CV_8UC2, [1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
let col = mat.col(1);
|
||||
|
||||
assert.equal(col.isContinuous(), false);
|
||||
assert.equal(col.ptr(0, 0)[0], 3);
|
||||
assert.equal(col.ptr(0, 0)[1], 4);
|
||||
assert.equal(col.ptr(1, 0)[0], 7);
|
||||
assert.equal(col.ptr(1, 0)[1], 8);
|
||||
|
||||
col.delete();
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// Mat::row(int)
|
||||
{
|
||||
let mat = cv.Mat.zeros(5, 5, cv.CV_8UC2);
|
||||
let row = mat.row(1);
|
||||
let view = row.data;
|
||||
assert.equal(view[0], 0);
|
||||
assert.equal(view[4], 0);
|
||||
|
||||
row.delete();
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// Mat::convertTo(Mat, int, double, double)
|
||||
{
|
||||
let mat = cv.Mat.ones(5, 5, cv.CV_8UC3);
|
||||
let grayMat = cv.Mat.zeros(5, 5, cv.CV_8UC1);
|
||||
|
||||
mat.convertTo(grayMat, cv.CV_8U, 2, 1);
|
||||
// dest = 2 * source(x, y) + 1.
|
||||
let view = grayMat.data;
|
||||
assert.equal(view[0], (1 * 2) + 1);
|
||||
|
||||
mat.convertTo(grayMat, cv.CV_8U);
|
||||
// dest = 1 * source(x, y) + 0.
|
||||
assert.equal(view[0], 1);
|
||||
|
||||
mat.convertTo(grayMat, cv.CV_8U, 2);
|
||||
// dest = 2 * source(x, y) + 0.
|
||||
assert.equal(view[0], 2);
|
||||
|
||||
grayMat.delete();
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
// split
|
||||
{
|
||||
const R =7;
|
||||
const G =13;
|
||||
const B =29;
|
||||
|
||||
let mat = cv.Mat.ones(5, 5, cv.CV_8UC3);
|
||||
let view = mat.data;
|
||||
view[0] = R;
|
||||
view[1] = G;
|
||||
view[2] = B;
|
||||
|
||||
let bgrPlanes = new cv.MatVector();
|
||||
cv.split(mat, bgrPlanes);
|
||||
assert.equal(bgrPlanes.size(), 3);
|
||||
|
||||
let rMat = bgrPlanes.get(0);
|
||||
view = rMat.data;
|
||||
assert.equal(view[0], R);
|
||||
|
||||
let gMat = bgrPlanes.get(1);
|
||||
view = gMat.data;
|
||||
assert.equal(view[0], G);
|
||||
|
||||
let bMat = bgrPlanes.get(2);
|
||||
view = bMat.data;
|
||||
assert.equal(view[0], B);
|
||||
|
||||
mat.delete();
|
||||
rMat.delete();
|
||||
gMat.delete();
|
||||
bgrPlanes.delete();
|
||||
bMat.delete();
|
||||
}
|
||||
|
||||
// elemSize
|
||||
{
|
||||
let mat = cv.Mat.ones(5, 5, cv.CV_8UC3);
|
||||
assert.equal(mat.elemSize(), 3);
|
||||
assert.equal(mat.elemSize1(), 1);
|
||||
|
||||
let mat2 = cv.Mat.zeros(5, 5, cv.CV_8UC1);
|
||||
assert.equal(mat2.elemSize(), 1);
|
||||
assert.equal(mat2.elemSize1(), 1);
|
||||
|
||||
let mat3 = cv.Mat.eye(5, 5, cv.CV_16UC3);
|
||||
assert.equal(mat3.elemSize(), 2 * 3);
|
||||
assert.equal(mat3.elemSize1(), 2);
|
||||
|
||||
mat.delete();
|
||||
mat2.delete();
|
||||
mat3.delete();
|
||||
}
|
||||
|
||||
// step
|
||||
{
|
||||
let mat = cv.Mat.ones(5, 5, cv.CV_8UC3);
|
||||
assert.equal(mat.step[0], 15);
|
||||
assert.equal(mat.step[1], 3);
|
||||
|
||||
let mat2 = cv.Mat.zeros(5, 5, cv.CV_8UC1);
|
||||
assert.equal(mat2.step[0], 5);
|
||||
assert.equal(mat2.step[1], 1);
|
||||
|
||||
let mat3 = cv.Mat.eye(5, 5, cv.CV_16UC3);
|
||||
assert.equal(mat3.step[0], 30);
|
||||
assert.equal(mat3.step[1], 6);
|
||||
|
||||
mat.delete();
|
||||
mat2.delete();
|
||||
mat3.delete();
|
||||
}
|
||||
|
||||
// dot
|
||||
{
|
||||
let mat = cv.Mat.ones(5, 5, cv.CV_8UC1);
|
||||
let mat2 = cv.Mat.eye(5, 5, cv.CV_8UC1);
|
||||
|
||||
assert.equal(mat.dot(mat), 25);
|
||||
assert.equal(mat.dot(mat2), 5);
|
||||
assert.equal(mat2.dot(mat2), 5);
|
||||
|
||||
mat.delete();
|
||||
mat2.delete();
|
||||
}
|
||||
|
||||
// mul
|
||||
{
|
||||
const FACTOR = 5;
|
||||
let mat = cv.Mat.ones(4, 4, cv.CV_8UC1);
|
||||
let mat2 = cv.Mat.eye(4, 4, cv.CV_8UC1);
|
||||
|
||||
let expected = new Uint8Array([FACTOR, 0, 0, 0,
|
||||
0, FACTOR, 0, 0,
|
||||
0, 0, FACTOR, 0,
|
||||
0, 0, 0, FACTOR]);
|
||||
let mat3 = mat.mul(mat2, FACTOR);
|
||||
|
||||
assert.deepEqual(mat3.data, expected);
|
||||
|
||||
mat.delete();
|
||||
mat2.delete();
|
||||
mat3.delete();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
QUnit.test('test mat access', function(assert) {
|
||||
// test memory view
|
||||
{
|
||||
let data = new Uint8Array([0, 0, 0, 255, 0, 1, 2, 3]);
|
||||
let dataPtr = cv._malloc(8);
|
||||
|
||||
let dataHeap = new Uint8Array(cv.HEAPU8.buffer, dataPtr, 8);
|
||||
dataHeap.set(new Uint8Array(data.buffer));
|
||||
|
||||
let mat = new cv.Mat(8, 1, cv.CV_8UC1, dataPtr, 0);
|
||||
|
||||
|
||||
let unsignedCharView = new Uint8Array(data.buffer);
|
||||
let charView = new Int8Array(data.buffer);
|
||||
let shortView = new Int16Array(data.buffer);
|
||||
let unsignedShortView = new Uint16Array(data.buffer);
|
||||
let intView = new Int32Array(data.buffer);
|
||||
let float32View = new Float32Array(data.buffer);
|
||||
let float64View = new Float64Array(data.buffer);
|
||||
|
||||
|
||||
assert.deepEqual(unsignedCharView, mat.data);
|
||||
assert.deepEqual(charView, mat.data8S);
|
||||
assert.deepEqual(shortView, mat.data16S);
|
||||
assert.deepEqual(unsignedShortView, mat.data16U);
|
||||
assert.deepEqual(intView, mat.data32S);
|
||||
assert.deepEqual(float32View, mat.data32F);
|
||||
assert.deepEqual(float64View, mat.data64F);
|
||||
}
|
||||
|
||||
// test ucharAt(i)
|
||||
{
|
||||
let data = new Uint8Array([0, 0, 0, 255, 0, 1, 2, 3]);
|
||||
let dataPtr = cv._malloc(8);
|
||||
|
||||
let dataHeap = new Uint8Array(cv.HEAPU8.buffer, dataPtr, 8);
|
||||
dataHeap.set(new Uint8Array(data.buffer));
|
||||
|
||||
let mat = new cv.Mat(8, 1, cv.CV_8UC1, dataPtr, 0);
|
||||
|
||||
assert.equal(mat.ucharAt(0), 0);
|
||||
assert.equal(mat.ucharAt(1), 0);
|
||||
assert.equal(mat.ucharAt(2), 0);
|
||||
assert.equal(mat.ucharAt(3), 255);
|
||||
assert.equal(mat.ucharAt(4), 0);
|
||||
assert.equal(mat.ucharAt(5), 1);
|
||||
assert.equal(mat.ucharAt(6), 2);
|
||||
assert.equal(mat.ucharAt(7), 3);
|
||||
}
|
||||
|
||||
// test ushortAt(i)
|
||||
{
|
||||
let data = new Uint16Array([0, 1000, 65000, 255, 0, 1, 2, 3]);
|
||||
let dataPtr = cv._malloc(16);
|
||||
|
||||
let dataHeap = new Uint16Array(cv.HEAPU8.buffer, dataPtr, 8);
|
||||
dataHeap.set(new Uint16Array(data.buffer));
|
||||
|
||||
let mat = new cv.Mat(8, 1, cv.CV_16SC1, dataPtr, 0);
|
||||
|
||||
assert.equal(mat.ushortAt(0), 0);
|
||||
assert.equal(mat.ushortAt(1), 1000);
|
||||
assert.equal(mat.ushortAt(2), 65000);
|
||||
assert.equal(mat.ushortAt(3), 255);
|
||||
assert.equal(mat.ushortAt(4), 0);
|
||||
assert.equal(mat.ushortAt(5), 1);
|
||||
assert.equal(mat.ushortAt(6), 2);
|
||||
assert.equal(mat.ushortAt(7), 3);
|
||||
}
|
||||
|
||||
// test intAt(i)
|
||||
{
|
||||
let data = new Int32Array([0, -1000, 65000, 255, -2000000, -1, 2, 3]);
|
||||
let dataPtr = cv._malloc(32);
|
||||
|
||||
let dataHeap = new Int32Array(cv.HEAPU32.buffer, dataPtr, 8);
|
||||
dataHeap.set(new Int32Array(data.buffer));
|
||||
|
||||
let mat = new cv.Mat(8, 1, cv.CV_32SC1, dataPtr, 0);
|
||||
|
||||
assert.equal(mat.intAt(0), 0);
|
||||
assert.equal(mat.intAt(1), -1000);
|
||||
assert.equal(mat.intAt(2), 65000);
|
||||
assert.equal(mat.intAt(3), 255);
|
||||
assert.equal(mat.intAt(4), -2000000);
|
||||
assert.equal(mat.intAt(5), -1);
|
||||
assert.equal(mat.intAt(6), 2);
|
||||
assert.equal(mat.intAt(7), 3);
|
||||
}
|
||||
|
||||
// test floatAt(i)
|
||||
{
|
||||
const EPSILON = 0.001;
|
||||
let data = new Float32Array([0, -10.5, 650.001, 255, -20.1, -1.2, 2, 3.5]);
|
||||
let dataPtr = cv._malloc(32);
|
||||
|
||||
let dataHeap = new Float32Array(cv.HEAPU32.buffer, dataPtr, 8);
|
||||
dataHeap.set(new Float32Array(data.buffer));
|
||||
|
||||
let mat = new cv.Mat(8, 1, cv.CV_32FC1, dataPtr, 0);
|
||||
|
||||
assert.equal(Math.abs(mat.floatAt(0)-0) < EPSILON, true);
|
||||
assert.equal(Math.abs(mat.floatAt(1)+10.5) < EPSILON, true);
|
||||
assert.equal(Math.abs(mat.floatAt(2)-650.001) < EPSILON, true);
|
||||
assert.equal(Math.abs(mat.floatAt(3)-255) < EPSILON, true);
|
||||
assert.equal(Math.abs(mat.floatAt(4)+20.1) < EPSILON, true);
|
||||
assert.equal(Math.abs(mat.floatAt(5)+1.2) < EPSILON, true);
|
||||
assert.equal(Math.abs(mat.floatAt(6)-2) < EPSILON, true);
|
||||
assert.equal(Math.abs(mat.floatAt(7)-3.5) < EPSILON, true);
|
||||
}
|
||||
|
||||
// test intAt(i,j)
|
||||
{
|
||||
let mat = cv.Mat.eye({height: 3, width: 3}, cv.CV_32SC1);
|
||||
|
||||
assert.equal(mat.intAt(0, 0), 1);
|
||||
assert.equal(mat.intAt(0, 1), 0);
|
||||
assert.equal(mat.intAt(0, 2), 0);
|
||||
assert.equal(mat.intAt(1, 0), 0);
|
||||
assert.equal(mat.intAt(1, 1), 1);
|
||||
assert.equal(mat.intAt(1, 2), 0);
|
||||
assert.equal(mat.intAt(2, 0), 0);
|
||||
assert.equal(mat.intAt(2, 1), 0);
|
||||
assert.equal(mat.intAt(2, 2), 1);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_mat_operations', function(assert) {
|
||||
// test minMaxLoc
|
||||
{
|
||||
let src = cv.Mat.ones(4, 4, cv.CV_8UC1);
|
||||
|
||||
src.data[2] = 0;
|
||||
src.data[5] = 2;
|
||||
|
||||
let result = cv.minMaxLoc(src);
|
||||
|
||||
assert.equal(result.minVal, 0);
|
||||
assert.equal(result.maxVal, 2);
|
||||
assert.deepEqual(result.minLoc, {x: 2, y: 0});
|
||||
assert.deepEqual(result.maxLoc, {x: 1, y: 1});
|
||||
|
||||
src.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_mat_roi', function(assert) {
|
||||
// test minMaxLoc
|
||||
{
|
||||
let mat = cv.matFromArray(2, 2, cv.CV_8UC1, [0, 1, 2, 3]);
|
||||
let roi = mat.roi(new cv.Rect(1, 1, 1, 1));
|
||||
|
||||
assert.equal(roi.rows, 1);
|
||||
assert.equal(roi.cols, 1);
|
||||
assert.deepEqual(roi.data, new Uint8Array([mat.ucharAt(1, 1)]));
|
||||
|
||||
mat.delete();
|
||||
roi.delete();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
QUnit.test('test_mat_range', function(assert) {
|
||||
{
|
||||
let src = cv.matFromArray(2, 2, cv.CV_8UC1, [0, 1, 2, 3]);
|
||||
let mat = src.colRange(0, 1);
|
||||
|
||||
assert.equal(mat.isContinuous(), false);
|
||||
assert.equal(mat.rows, 2);
|
||||
assert.equal(mat.cols, 1);
|
||||
assert.equal(mat.ucharAt(0), 0);
|
||||
assert.equal(mat.ucharAt(1), 2);
|
||||
|
||||
mat.delete();
|
||||
|
||||
mat = src.colRange({start: 0, end: 1});
|
||||
|
||||
assert.equal(mat.isContinuous(), false);
|
||||
assert.equal(mat.rows, 2);
|
||||
assert.equal(mat.cols, 1);
|
||||
assert.equal(mat.ucharAt(0), 0);
|
||||
assert.equal(mat.ucharAt(1), 2);
|
||||
|
||||
mat.delete();
|
||||
|
||||
mat = src.rowRange(1, 2);
|
||||
|
||||
assert.equal(mat.rows, 1);
|
||||
assert.equal(mat.cols, 2);
|
||||
assert.deepEqual(mat.data, new Uint8Array([2, 3]));
|
||||
|
||||
mat.delete();
|
||||
|
||||
mat = src.rowRange({start: 1, end: 2});
|
||||
|
||||
assert.equal(mat.rows, 1);
|
||||
assert.equal(mat.cols, 2);
|
||||
assert.deepEqual(mat.data, new Uint8Array([2, 3]));
|
||||
|
||||
mat.delete();
|
||||
|
||||
src.delete();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('test_mat_diag', function(assert) {
|
||||
// test diag
|
||||
{
|
||||
let mat = cv.matFromArray(3, 3, cv.CV_8UC1, [0, 1, 2, 3, 4, 5, 6, 7, 8]);
|
||||
let d = mat.diag();
|
||||
let d1 = mat.diag(1);
|
||||
let d2 = mat.diag(-1);
|
||||
|
||||
assert.equal(mat.isContinuous(), true);
|
||||
assert.equal(d.isContinuous(), false);
|
||||
assert.equal(d1.isContinuous(), false);
|
||||
assert.equal(d2.isContinuous(), false);
|
||||
|
||||
assert.equal(d.ucharAt(0), 0);
|
||||
assert.equal(d.ucharAt(1), 4);
|
||||
assert.equal(d.ucharAt(2), 8);
|
||||
|
||||
assert.equal(d1.ucharAt(0), 1);
|
||||
assert.equal(d1.ucharAt(1), 5);
|
||||
|
||||
assert.equal(d2.ucharAt(0), 3);
|
||||
assert.equal(d2.ucharAt(1), 7);
|
||||
|
||||
mat.delete();
|
||||
d.delete();
|
||||
d1.delete();
|
||||
d2.delete();
|
||||
}
|
||||
});
|
||||
161
Lib/opencv/sources/modules/js/test/test_objdetect.js
Normal file
161
Lib/opencv/sources/modules/js/test/test_objdetect.js
Normal file
@@ -0,0 +1,161 @@
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
// Author: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
|
||||
//
|
||||
// LICENSE AGREEMENT
|
||||
// Copyright (c) 2015 The Regents of the University of California (Regents)
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the University nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
// The environment is Node.js
|
||||
var cv = require('./opencv.js'); // eslint-disable-line no-var
|
||||
cv.FS_createLazyFile('/', 'haarcascade_frontalface_default.xml', // eslint-disable-line new-cap
|
||||
'haarcascade_frontalface_default.xml', true, false);
|
||||
}
|
||||
|
||||
QUnit.module('Object Detection', {});
|
||||
QUnit.test('Cascade classification', function(assert) {
|
||||
// Group rectangle
|
||||
{
|
||||
let rectList = new cv.RectVector();
|
||||
let weights = new cv.IntVector();
|
||||
let groupThreshold = 1;
|
||||
const eps = 0.2;
|
||||
|
||||
let rect1 = new cv.Rect(1, 2, 3, 4);
|
||||
let rect2 = new cv.Rect(1, 4, 2, 3);
|
||||
|
||||
rectList.push_back(rect1);
|
||||
rectList.push_back(rect2);
|
||||
|
||||
cv.groupRectangles(rectList, weights, groupThreshold, eps);
|
||||
|
||||
|
||||
rectList.delete();
|
||||
weights.delete();
|
||||
}
|
||||
|
||||
// CascadeClassifier
|
||||
{
|
||||
let classifier = new cv.CascadeClassifier();
|
||||
const modelPath = '/haarcascade_frontalface_default.xml';
|
||||
|
||||
assert.equal(classifier.empty(), true);
|
||||
|
||||
|
||||
classifier.load(modelPath);
|
||||
assert.equal(classifier.empty(), false);
|
||||
|
||||
let image = cv.Mat.eye({height: 10, width: 10}, cv.CV_8UC3);
|
||||
let objects = new cv.RectVector();
|
||||
let numDetections = new cv.IntVector();
|
||||
const scaleFactor = 1.1;
|
||||
const minNeighbors = 3;
|
||||
const flags = 0;
|
||||
const minSize = {height: 0, width: 0};
|
||||
const maxSize = {height: 10, width: 10};
|
||||
|
||||
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor,
|
||||
minNeighbors, flags, minSize, maxSize);
|
||||
|
||||
// test default parameters
|
||||
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor,
|
||||
minNeighbors, flags, minSize);
|
||||
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor,
|
||||
minNeighbors, flags);
|
||||
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor,
|
||||
minNeighbors);
|
||||
classifier.detectMultiScale2(image, objects, numDetections, scaleFactor);
|
||||
|
||||
classifier.delete();
|
||||
objects.delete();
|
||||
numDetections.delete();
|
||||
}
|
||||
|
||||
// HOGDescriptor
|
||||
{
|
||||
let hog = new cv.HOGDescriptor();
|
||||
let mat = new cv.Mat({height: 10, width: 10}, cv.CV_8UC1);
|
||||
let descriptors = new cv.FloatVector();
|
||||
let locations = new cv.PointVector();
|
||||
|
||||
|
||||
assert.equal(hog.winSize.height, 128);
|
||||
assert.equal(hog.winSize.width, 64);
|
||||
assert.equal(hog.nbins, 9);
|
||||
assert.equal(hog.derivAperture, 1);
|
||||
assert.equal(hog.winSigma, -1);
|
||||
assert.equal(hog.histogramNormType, 0);
|
||||
assert.equal(hog.nlevels, 64);
|
||||
|
||||
hog.nlevels = 32;
|
||||
assert.equal(hog.nlevels, 32);
|
||||
|
||||
hog.delete();
|
||||
mat.delete();
|
||||
descriptors.delete();
|
||||
locations.delete();
|
||||
}
|
||||
});
|
||||
116
Lib/opencv/sources/modules/js/test/test_photo.js
Normal file
116
Lib/opencv/sources/modules/js/test/test_photo.js
Normal file
@@ -0,0 +1,116 @@
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
|
||||
// Author : Rijubrata Bhaumik, Intel Corporation. rijubrata.bhaumik[at]intel[dot]com
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
// The environment is Node.js
|
||||
var cv = require('./opencv.js'); // eslint-disable-line no-var
|
||||
}
|
||||
|
||||
|
||||
QUnit.module('Photo', {});
|
||||
|
||||
QUnit.test('test_photo', function(assert) {
|
||||
// CalibrateDebevec
|
||||
{
|
||||
let calibration = new cv.CalibrateDebevec();
|
||||
assert.ok(true, calibration);
|
||||
//let response = calibration.process(images, exposures);
|
||||
}
|
||||
// CalibrateRobertson
|
||||
{
|
||||
let calibration = new cv.CalibrateRobertson();
|
||||
assert.ok(true, calibration);
|
||||
//let response = calibration.process(images, exposures);
|
||||
}
|
||||
|
||||
// MergeDebevec
|
||||
{
|
||||
let merge = new cv.MergeDebevec();
|
||||
assert.ok(true, merge);
|
||||
//let hdr = merge.process(images, exposures, response);
|
||||
}
|
||||
// MergeMertens
|
||||
{
|
||||
let merge = new cv.MergeMertens();
|
||||
assert.ok(true, merge);
|
||||
//let hdr = merge.process(images, exposures, response);
|
||||
}
|
||||
// MergeRobertson
|
||||
{
|
||||
let merge = new cv.MergeRobertson();
|
||||
assert.ok(true, merge);
|
||||
//let hdr = merge.process(images, exposures, response);
|
||||
}
|
||||
|
||||
// TonemapDrago
|
||||
{
|
||||
let tonemap = new cv.TonemapDrago();
|
||||
assert.ok(true, tonemap);
|
||||
// let ldr = new cv.Mat();
|
||||
// let retval = tonemap.process(hdr, ldr);
|
||||
}
|
||||
// TonemapMantiuk
|
||||
{
|
||||
let tonemap = new cv.TonemapMantiuk();
|
||||
assert.ok(true, tonemap);
|
||||
// let ldr = new cv.Mat();
|
||||
// let retval = tonemap.process(hdr, ldr);
|
||||
}
|
||||
// TonemapReinhard
|
||||
{
|
||||
let tonemap = new cv.TonemapReinhard();
|
||||
assert.ok(true, tonemap);
|
||||
// let ldr = new cv.Mat();
|
||||
// let retval = tonemap.process(hdr, ldr);
|
||||
}
|
||||
// Inpaint
|
||||
{
|
||||
let src = new cv.Mat(100, 100, cv.CV_8UC3, new cv.Scalar(127, 127, 127, 255));
|
||||
let mask = new cv.Mat(100, 100, cv.CV_8UC1, new cv.Scalar(0, 0, 0, 0));
|
||||
let dst = new cv.Mat();
|
||||
cv.line(mask, new cv.Point(10, 50), new cv.Point(90, 50), new cv.Scalar(255, 255, 255, 255),5);
|
||||
cv.inpaint(src, mask, dst, 3, cv.INPAINT_TELEA);
|
||||
assert.equal(dst.rows, 100);
|
||||
assert.equal(dst.cols, 100);
|
||||
assert.equal(dst.channels(), 3);
|
||||
}
|
||||
});
|
||||
253
Lib/opencv/sources/modules/js/test/test_utils.js
Normal file
253
Lib/opencv/sources/modules/js/test/test_utils.js
Normal file
@@ -0,0 +1,253 @@
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
// Author: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
|
||||
//
|
||||
// LICENSE AGREEMENT
|
||||
// Copyright (c) 2015 The Regents of the University of California (Regents)
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the University nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
// The environment is Node.js
|
||||
var cv = require('./opencv.js'); // eslint-disable-line no-var
|
||||
}
|
||||
QUnit.module('Utils', {});
|
||||
QUnit.test('Test vectors', function(assert) {
|
||||
{
|
||||
let pointVector = new cv.PointVector();
|
||||
for (let i=0; i<100; ++i) {
|
||||
pointVector.push_back({x: i, y: 2*i});
|
||||
}
|
||||
|
||||
assert.equal(pointVector.size(), 100);
|
||||
|
||||
let index = 10;
|
||||
let item = pointVector.get(index);
|
||||
assert.equal(item.x, index);
|
||||
assert.equal(item.y, 2*index);
|
||||
|
||||
index = 0;
|
||||
item = pointVector.get(index);
|
||||
assert.equal(item.x, index);
|
||||
assert.equal(item.y, 2*index);
|
||||
|
||||
index = 99;
|
||||
item = pointVector.get(index);
|
||||
assert.equal(item.x, index);
|
||||
assert.equal(item.y, 2*index);
|
||||
|
||||
pointVector.delete();
|
||||
}
|
||||
|
||||
{
|
||||
let pointVector = new cv.PointVector();
|
||||
for (let i=0; i<100; ++i) {
|
||||
pointVector.push_back(new cv.Point(i, 2*i));
|
||||
}
|
||||
|
||||
pointVector.push_back(new cv.Point());
|
||||
|
||||
assert.equal(pointVector.size(), 101);
|
||||
|
||||
let index = 10;
|
||||
let item = pointVector.get(index);
|
||||
assert.equal(item.x, index);
|
||||
assert.equal(item.y, 2*index);
|
||||
|
||||
index = 0;
|
||||
item = pointVector.get(index);
|
||||
assert.equal(item.x, index);
|
||||
assert.equal(item.y, 2*index);
|
||||
|
||||
index = 99;
|
||||
item = pointVector.get(index);
|
||||
assert.equal(item.x, index);
|
||||
assert.equal(item.y, 2*index);
|
||||
|
||||
index = 100;
|
||||
item = pointVector.get(index);
|
||||
assert.equal(item.x, 0);
|
||||
assert.equal(item.y, 0);
|
||||
|
||||
pointVector.delete();
|
||||
}
|
||||
});
|
||||
QUnit.test('Test Rect', function(assert) {
|
||||
let rectVector = new cv.RectVector();
|
||||
let rect = {x: 1, y: 2, width: 3, height: 4};
|
||||
rectVector.push_back(rect);
|
||||
rectVector.push_back(new cv.Rect());
|
||||
rectVector.push_back(new cv.Rect(rect));
|
||||
rectVector.push_back(new cv.Rect({x: 5, y: 6}, {width: 7, height: 8}));
|
||||
rectVector.push_back(new cv.Rect(9, 10, 11, 12));
|
||||
|
||||
assert.equal(rectVector.size(), 5);
|
||||
|
||||
let item = rectVector.get(0);
|
||||
assert.equal(item.x, 1);
|
||||
assert.equal(item.y, 2);
|
||||
assert.equal(item.width, 3);
|
||||
assert.equal(item.height, 4);
|
||||
|
||||
item = rectVector.get(1);
|
||||
assert.equal(item.x, 0);
|
||||
assert.equal(item.y, 0);
|
||||
assert.equal(item.width, 0);
|
||||
assert.equal(item.height, 0);
|
||||
|
||||
item = rectVector.get(2);
|
||||
assert.equal(item.x, 1);
|
||||
assert.equal(item.y, 2);
|
||||
assert.equal(item.width, 3);
|
||||
assert.equal(item.height, 4);
|
||||
|
||||
item = rectVector.get(3);
|
||||
assert.equal(item.x, 5);
|
||||
assert.equal(item.y, 6);
|
||||
assert.equal(item.width, 7);
|
||||
assert.equal(item.height, 8);
|
||||
|
||||
item = rectVector.get(4);
|
||||
assert.equal(item.x, 9);
|
||||
assert.equal(item.y, 10);
|
||||
assert.equal(item.width, 11);
|
||||
assert.equal(item.height, 12);
|
||||
|
||||
rectVector.delete();
|
||||
});
|
||||
QUnit.test('Test Size', function(assert) {
|
||||
{
|
||||
let mat = new cv.Mat();
|
||||
mat.create({width: 5, height: 10}, cv.CV_8UC4);
|
||||
let size = mat.size();
|
||||
|
||||
assert.ok(mat.type() === cv.CV_8UC4);
|
||||
assert.ok(size.height === 10);
|
||||
assert.ok(size.width === 5);
|
||||
assert.ok(mat.channels() === 4);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
|
||||
{
|
||||
let mat = new cv.Mat();
|
||||
mat.create(new cv.Size(5, 10), cv.CV_8UC4);
|
||||
let size = mat.size();
|
||||
|
||||
assert.ok(mat.type() === cv.CV_8UC4);
|
||||
assert.ok(size.height === 10);
|
||||
assert.ok(size.width === 5);
|
||||
assert.ok(mat.channels() === 4);
|
||||
|
||||
mat.delete();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
QUnit.test('test_rotated_rect', function(assert) {
|
||||
{
|
||||
let rect = {center: {x: 100, y: 100}, size: {height: 100, width: 50}, angle: 30};
|
||||
|
||||
assert.equal(rect.center.x, 100);
|
||||
assert.equal(rect.center.y, 100);
|
||||
assert.equal(rect.angle, 30);
|
||||
assert.equal(rect.size.height, 100);
|
||||
assert.equal(rect.size.width, 50);
|
||||
}
|
||||
|
||||
{
|
||||
let rect = new cv.RotatedRect();
|
||||
|
||||
assert.equal(rect.center.x, 0);
|
||||
assert.equal(rect.center.y, 0);
|
||||
assert.equal(rect.angle, 0);
|
||||
assert.equal(rect.size.height, 0);
|
||||
assert.equal(rect.size.width, 0);
|
||||
|
||||
let points = cv.RotatedRect.points(rect);
|
||||
|
||||
assert.equal(points[0].x, 0);
|
||||
assert.equal(points[0].y, 0);
|
||||
assert.equal(points[1].x, 0);
|
||||
assert.equal(points[1].y, 0);
|
||||
assert.equal(points[2].x, 0);
|
||||
assert.equal(points[2].y, 0);
|
||||
assert.equal(points[3].x, 0);
|
||||
assert.equal(points[3].y, 0);
|
||||
}
|
||||
|
||||
{
|
||||
let rect = new cv.RotatedRect({x: 100, y: 100}, {height: 100, width: 50}, 30);
|
||||
|
||||
assert.equal(rect.center.x, 100);
|
||||
assert.equal(rect.center.y, 100);
|
||||
assert.equal(rect.angle, 30);
|
||||
assert.equal(rect.size.height, 100);
|
||||
assert.equal(rect.size.width, 50);
|
||||
|
||||
let points = cv.RotatedRect.points(rect);
|
||||
|
||||
assert.equal(points[0].x, cv.RotatedRect.boundingRect2f(rect).x);
|
||||
assert.equal(points[1].y, cv.RotatedRect.boundingRect2f(rect).y);
|
||||
}
|
||||
});
|
||||
107
Lib/opencv/sources/modules/js/test/test_video.js
Normal file
107
Lib/opencv/sources/modules/js/test/test_video.js
Normal file
@@ -0,0 +1,107 @@
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
// Author: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
|
||||
//
|
||||
// LICENSE AGREEMENT
|
||||
// Copyright (c) 2015 The Regents of the University of California (Regents)
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// 1. Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// 2. Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// 3. Neither the name of the University nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
|
||||
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
|
||||
if (typeof module !== 'undefined' && module.exports) {
|
||||
// The environment is Node.js
|
||||
var cv = require('./opencv.js'); // eslint-disable-line no-var
|
||||
}
|
||||
|
||||
QUnit.module('Video', {});
|
||||
QUnit.test('Background Segmentation', function(assert) {
|
||||
// BackgroundSubtractorMOG2
|
||||
{
|
||||
const history = 600;
|
||||
const varThreshold = 15;
|
||||
const detectShadows = true;
|
||||
|
||||
let mog2 = new cv.BackgroundSubtractorMOG2(history, varThreshold, detectShadows);
|
||||
|
||||
assert.equal(mog2 instanceof cv.BackgroundSubtractorMOG2, true);
|
||||
|
||||
mog2.delete();
|
||||
|
||||
mog2 = new cv.BackgroundSubtractorMOG2();
|
||||
|
||||
assert.equal(mog2 instanceof cv.BackgroundSubtractorMOG2, true);
|
||||
|
||||
mog2.delete();
|
||||
|
||||
mog2 = new cv.BackgroundSubtractorMOG2(history);
|
||||
|
||||
assert.equal(mog2 instanceof cv.BackgroundSubtractorMOG2, true);
|
||||
|
||||
mog2.delete();
|
||||
|
||||
mog2 = new cv.BackgroundSubtractorMOG2(history, varThreshold);
|
||||
|
||||
assert.equal(mog2 instanceof cv.BackgroundSubtractorMOG2, true);
|
||||
|
||||
mog2.delete();
|
||||
}
|
||||
});
|
||||
109
Lib/opencv/sources/modules/js/test/tests.html
Normal file
109
Lib/opencv/sources/modules/js/test/tests.html
Normal file
@@ -0,0 +1,109 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>OpenCV JS Tests</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
|
||||
<link rel="stylesheet" href="http://code.jquery.com/qunit/qunit-1.20.0.css" type="text/css" media="screen">
|
||||
<style>
|
||||
body {
|
||||
font-family: Monospace;
|
||||
background-color: #ffffff;
|
||||
margin: 0px;
|
||||
}
|
||||
a {
|
||||
color: #0040ff;
|
||||
}
|
||||
</style>
|
||||
<script src="http://code.jquery.com/qunit/qunit-2.0.1.js"></script>
|
||||
<script type="text/javascript">
|
||||
QUnit.config.autostart = false;
|
||||
|
||||
QUnit.log(function(details) {
|
||||
if (details.result) {
|
||||
return;
|
||||
}
|
||||
var loc = details.module + ": " + details.name + ": ",
|
||||
output = "FAILED: " + loc + ( details.message ? details.message : "" )
|
||||
prefix = details.message ? ", " : "";
|
||||
|
||||
if (details.actual) {
|
||||
output += prefix + "expected: " + details.expected + ", actual: " + details.actual;
|
||||
prefix = ', ';
|
||||
}
|
||||
if (details.source) {
|
||||
output += prefix + details.source;
|
||||
}
|
||||
console.warn(output);
|
||||
});
|
||||
QUnit.done(function(details) {
|
||||
console.log("Total: " + details.total + " Failed: " + details.failed + " Passed: " + details.passed);
|
||||
console.log("Time(ms): " + details.runtime);
|
||||
});
|
||||
|
||||
// Helper for opencv.js (see below)
|
||||
var Module = {
|
||||
preRun: [function() {
|
||||
Module.FS_createPreloadedFile('/', 'haarcascade_frontalface_default.xml', 'haarcascade_frontalface_default.xml', true, false);
|
||||
}],
|
||||
postRun: [] ,
|
||||
onRuntimeInitialized: function() {
|
||||
console.log("Emscripten runtime is ready, launching QUnit tests...");
|
||||
//console.log(cv.getBuildInformation());
|
||||
QUnit.start();
|
||||
},
|
||||
print: (function() {
|
||||
var element = document.getElementById('output');
|
||||
if (element) element.value = ''; // clear browser cache
|
||||
return function(text) {
|
||||
console.log(text);
|
||||
if (element) {
|
||||
element.value += text + "\n";
|
||||
element.scrollTop = element.scrollHeight; // focus on bottom
|
||||
}
|
||||
};
|
||||
})(),
|
||||
printErr: function(text) {
|
||||
console.error(text);
|
||||
},
|
||||
setStatus: function(text) {
|
||||
console.log(text);
|
||||
},
|
||||
totalDependencies: 0
|
||||
};
|
||||
|
||||
Module.setStatus('Downloading...');
|
||||
window.onerror = function(event) {
|
||||
Module.setStatus('Exception thrown, see JavaScript console');
|
||||
Module.setStatus = function(text) {
|
||||
if (text) Module.printErr('[post-exception status] ' + text);
|
||||
};
|
||||
};
|
||||
|
||||
function opencvjs_LoadError() {
|
||||
Module.printErr('Failed to load/initialize opencv.js');
|
||||
QUnit.module('LoaderFatalError', {});
|
||||
QUnit.config.module = 'LoaderFatalError';
|
||||
QUnit.only("Failed to load OpenCV.js", function(assert) {
|
||||
assert.ok(false, "Can't load/initialize opencv.js");
|
||||
});
|
||||
QUnit.start();
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<div id="qunit"></div>
|
||||
<div id="qunit-fixture"></div>
|
||||
|
||||
<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_imgproc.js"></script>
|
||||
<script type="application/javascript" src="test_objdetect.js"></script>
|
||||
<script type="application/javascript" src="test_video.js"></script>
|
||||
<script type="application/javascript" src="test_photo.js"></script>
|
||||
<script type="application/javascript" src="test_features2d.js"></script>
|
||||
<script type="application/javascript" src="test_calib3d.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
61
Lib/opencv/sources/modules/js/test/tests.js
Normal file
61
Lib/opencv/sources/modules/js/test/tests.js
Normal file
@@ -0,0 +1,61 @@
|
||||
// //////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2013, OpenCV Foundation, all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
|
||||
let testrunner = require('node-qunit');
|
||||
testrunner.options.maxBlockDuration = 20000; // cause opencv_js.js need time to load
|
||||
|
||||
testrunner.run(
|
||||
{
|
||||
code: 'opencv.js',
|
||||
tests: ['test_mat.js', 'test_utils.js', 'test_imgproc.js',
|
||||
'test_objdetect.js', 'test_video.js', 'test_features2d.js',
|
||||
'test_photo.js',
|
||||
'test_calib3d.js'
|
||||
],
|
||||
},
|
||||
function(err, report) {
|
||||
console.log(report.failed + ' failed, ' + report.passed + ' passed');
|
||||
if (report.failed) {
|
||||
process.on('exit', function() {
|
||||
process.exit(1);
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user