Merge pull request #19771 from lionkunonly:opencvjsNodeFix

* fix the perf tests of OpenCV.js so that it can run on Node.js successfully

* do not modify the CMakeLists.txt

Co-authored-by: lionkun <871518554@qq.com>
pull/18237/head^2
Kun Liang 4 years ago committed by GitHub
parent 69341edfe6
commit 32d51313d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      modules/js/perf/base.js
  2. 9
      modules/js/perf/perf_helpfunc.js
  3. 5
      modules/js/perf/perf_imgproc/perf_blur.js
  4. 8
      modules/js/perf/perf_imgproc/perf_cvtcolor.js
  5. 5
      modules/js/perf/perf_imgproc/perf_dilate.js
  6. 5
      modules/js/perf/perf_imgproc/perf_erode.js
  7. 5
      modules/js/perf/perf_imgproc/perf_filter2D.js
  8. 5
      modules/js/perf/perf_imgproc/perf_gaussianBlur.js
  9. 5
      modules/js/perf/perf_imgproc/perf_medianBlur.js
  10. 5
      modules/js/perf/perf_imgproc/perf_pyrDown.js
  11. 5
      modules/js/perf/perf_imgproc/perf_remap.js
  12. 6
      modules/js/perf/perf_imgproc/perf_resize.js
  13. 5
      modules/js/perf/perf_imgproc/perf_scharr.js
  14. 5
      modules/js/perf/perf_imgproc/perf_sobel.js
  15. 5
      modules/js/perf/perf_imgproc/perf_threshold.js
  16. 7
      modules/js/perf/perf_imgproc/perf_warpAffine.js
  17. 7
      modules/js/perf/perf_imgproc/perf_warpPerspective.js

@ -1,5 +1,10 @@
if (typeof window === 'undefined') {
var cv = require("../opencv");
if (cv instanceof Promise) {
loadOpenCV();
} else {
cv.onRuntimeInitialized = perf;
}
}
let gCvSize;
@ -24,6 +29,10 @@ function getCvSize() {
return gCvSize;
}
async function loadOpenCV() {
cv = await cv;
}
if (typeof window === 'undefined') {
exports.getCvSize = getCvSize;
}

@ -1,3 +1,10 @@
const isNodeJs = (typeof window) === 'undefined'? true : false;
if(isNodeJs) {
var Base = require("./base");
global.getCvSize = Base.getCvSize;
}
var fillGradient = function(cv, img, delta=5) {
let ch = img.channels();
console.assert(!img.empty() && img.depth() == cv.CV_8U && ch <= 4);
@ -56,8 +63,8 @@ var smoothBorder = function(cv, img, color, delta=5) {
var cvtStr2cvSize = function(strSize) {
let size;
let cvSize = getCvSize();
switch(strSize) {
case "127,61": size = cvSize.szODD;break;
case '320,240': size = cvSize.szQVGA;break;

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,11 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.constructMode = HelpFunc.constructMode;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();
@ -25,7 +29,7 @@ function perf() {
}
let totalCaseNum, currentCaseId;
//extra color conversions supported implicitly
// extra color conversions supported implicitly
{
cv.CX_BGRA2HLS = cv.COLOR_COLORCVT_MAX + cv.COLOR_BGR2HLS,
cv.CX_BGRA2HLS_FULL = cv.COLOR_COLORCVT_MAX + cv.COLOR_BGR2HLS_FULL,

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,11 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.fillGradient = HelpFunc.fillGradient;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -17,7 +17,10 @@ function perf() {
if (isNodeJs) {
global.cv = cv;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase;
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -16,8 +16,13 @@ function perf() {
console.log('opencv.js loaded');
if (isNodeJs) {
global.cv = cv;
global.fillGradient = HelpFunc.fillGradient;
global.smoothBorder = HelpFunc.smoothBorder;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase
global.cvSize = Base.getCvSize();
} else {
enableButton();

@ -16,8 +16,13 @@ function perf() {
console.log('opencv.js loaded');
if (isNodeJs) {
global.cv = cv;
global.fillGradient = HelpFunc.fillGradient;
global.smoothBorder = HelpFunc.smoothBorder;
global.combine = HelpFunc.combine;
global.cvtStr2cvSize = HelpFunc.cvtStr2cvSize;
global.log = HelpFunc.log;
global.decodeParams2Case = HelpFunc.decodeParams2Case;
global.setBenchmarkSuite = HelpFunc.setBenchmarkSuite;
global.addKernelCase = HelpFunc.addKernelCase
global.cvSize = Base.getCvSize();
} else {
enableButton();

Loading…
Cancel
Save