Merge pull request #25732 from dkurt:opencv_js_tests_update

Fix OpenCV.js tests #25732

### Pull Request Readiness Checklist

* Firefox tests passed

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [x] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Dmitry Kurtaev 2024-06-11 12:01:51 +03:00 committed by GitHub
parent 8e9307074c
commit a03b813167
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 29 additions and 47 deletions

View File

@ -0,0 +1,14 @@
// 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 (cv instanceof Promise) {
QUnit.test("init_cv", (assert) => {
const done = assert.async();
assert.ok(true);
cv.then((ready_cv) => {
cv = ready_cv;
done();
});
});
}

View File

@ -2,11 +2,6 @@
// 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) {

View File

@ -2,11 +2,6 @@
// It is subject to the license terms in the LICENSE file found in the top-level directory
// of this distribution and at http://opencv.org/license.html.
if (typeof module !== 'undefined' && module.exports) {
// The environment is Node.js
var cv = require('./opencv.js'); // eslint-disable-line no-var
}
QUnit.module('Core', {});
QUnit.test('test_LUT', function(assert) {

View File

@ -2,11 +2,6 @@
// 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;

View File

@ -68,11 +68,6 @@
// 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) {

View File

@ -68,11 +68,6 @@
// 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('CoreMat', {});
QUnit.test('test_mat_creation', function(assert) {

View File

@ -68,11 +68,11 @@
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
var haarcascade_data = undefined;
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);
let fs = require("fs");
haarcascade_data = fs.readFileSync("haarcascade_frontalface_default.xml");
}
QUnit.module('Object Detection', {});
@ -99,6 +99,10 @@ QUnit.test('Cascade classification', function(assert) {
// CascadeClassifier
{
if (haarcascade_data) {
cv.FS_createDataFile("/", "haarcascade_frontalface_default.xml", haarcascade_data, true, false, false);
}
let classifier = new cv.CascadeClassifier();
const modelPath = '/haarcascade_frontalface_default.xml';

View File

@ -40,12 +40,6 @@
// 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) {

View File

@ -67,10 +67,6 @@
// 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) {
{

View File

@ -67,11 +67,6 @@
// 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

View File

@ -43,8 +43,9 @@ testrunner.options.maxBlockDuration = 20000; // cause opencv_js.js need time to
testrunner.run(
{
code: 'opencv.js',
tests: ['test_mat.js',
code: {path: "opencv.js", namespace: "cv"},
tests: ['init_cv.js',
'test_mat.js',
'test_utils.js',
'test_core.js',
'test_imgproc.js',
@ -57,7 +58,10 @@ testrunner.run(
},
function(err, report) {
console.log(report.failed + ' failed, ' + report.passed + ' passed');
if (report.failed) {
if (report.failed || err) {
if (err) {
console.log(err);
}
process.on('exit', function() {
process.exit(1);
});

View File

@ -192,7 +192,7 @@ class Builder:
if self.options.simd:
flags += "-msimd128 "
if self.options.build_flags:
flags += self.options.build_flags
flags += self.options.build_flags + " "
if self.options.webnn:
flags += "-s USE_WEBNN=1 "
flags += "-s EXPORTED_FUNCTIONS=\"['_malloc', '_free']\""