js: fix helper.js to not trigger warnings

This commit is contained in:
Vincent Rabaud 2024-12-18 11:49:08 +01:00
parent d369cf6d50
commit 874e57512e

View File

@ -66,7 +66,6 @@ Module['imread'] = function(imageSource) {
ctx = canvas.getContext('2d'); ctx = canvas.getContext('2d');
} else { } else {
throw new Error('Please input the valid canvas or img id.'); throw new Error('Please input the valid canvas or img id.');
return;
} }
var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height); var imgData = ctx.getImageData(0, 0, canvas.width, canvas.height);
@ -82,11 +81,9 @@ Module['imshow'] = function(canvasSource, mat) {
} }
if (!(canvas instanceof HTMLCanvasElement)) { if (!(canvas instanceof HTMLCanvasElement)) {
throw new Error('Please input the valid canvas element or id.'); throw new Error('Please input the valid canvas element or id.');
return;
} }
if (!(mat instanceof cv.Mat)) { if (!(mat instanceof cv.Mat)) {
throw new Error('Please input the valid cv.Mat instance.'); throw new Error('Please input the valid cv.Mat instance.');
return;
} }
// convert the mat type to cv.CV_8U // convert the mat type to cv.CV_8U
@ -108,7 +105,6 @@ Module['imshow'] = function(canvasSource, mat) {
break; break;
default: default:
throw new Error('Bad number of channels (Source image must have 1, 3 or 4 channels)'); throw new Error('Bad number of channels (Source image must have 1, 3 or 4 channels)');
return;
} }
var imgData = new ImageData(new Uint8ClampedArray(img.data), img.cols, img.rows); var imgData = new ImageData(new Uint8ClampedArray(img.data), img.cols, img.rows);
var ctx = canvas.getContext('2d'); var ctx = canvas.getContext('2d');
@ -128,7 +124,6 @@ Module['VideoCapture'] = function(videoSource) {
} }
if (!(video instanceof HTMLVideoElement)) { if (!(video instanceof HTMLVideoElement)) {
throw new Error('Please input the valid video element or id.'); throw new Error('Please input the valid video element or id.');
return;
} }
var canvas = document.createElement('canvas'); var canvas = document.createElement('canvas');
canvas.width = video.width; canvas.width = video.width;
@ -138,15 +133,12 @@ Module['VideoCapture'] = function(videoSource) {
this.read = function(frame) { this.read = function(frame) {
if (!(frame instanceof cv.Mat)) { if (!(frame instanceof cv.Mat)) {
throw new Error('Please input the valid cv.Mat instance.'); throw new Error('Please input the valid cv.Mat instance.');
return;
} }
if (frame.type() !== cv.CV_8UC4) { if (frame.type() !== cv.CV_8UC4) {
throw new Error('Bad type of input mat: the type should be cv.CV_8UC4.'); throw new Error('Bad type of input mat: the type should be cv.CV_8UC4.');
return;
} }
if (frame.cols !== video.width || frame.rows !== video.height) { if (frame.cols !== video.width || frame.rows !== video.height) {
throw new Error('Bad size of input mat: the size should be same as the video.'); throw new Error('Bad size of input mat: the size should be same as the video.');
return;
} }
ctx.drawImage(video, 0, 0, video.width, video.height); ctx.drawImage(video, 0, 0, video.width, video.height);
frame.data.set(ctx.getImageData(0, 0, video.width, video.height).data); frame.data.set(ctx.getImageData(0, 0, video.width, video.height).data);
@ -263,7 +255,7 @@ function Scalar(v0, v1, v2, v3) {
Scalar.prototype = new Array; // eslint-disable-line no-array-constructor Scalar.prototype = new Array; // eslint-disable-line no-array-constructor
Scalar.all = function(v) { Scalar.all = function(v) {
return new Scalar(v, v, v, v); return Scalar(v, v, v, v);
}; };
Module['Scalar'] = Scalar; Module['Scalar'] = Scalar;
@ -273,8 +265,8 @@ function MinMaxLoc() {
case 0: { case 0: {
this.minVal = 0; this.minVal = 0;
this.maxVal = 0; this.maxVal = 0;
this.minLoc = new Point(); this.minLoc = Point(0, 0);
this.maxLoc = new Point(); this.maxLoc = Point(0, 0);
break; break;
} }
case 4: { case 4: {
@ -295,7 +287,7 @@ Module['MinMaxLoc'] = MinMaxLoc;
function Circle() { function Circle() {
switch (arguments.length) { switch (arguments.length) {
case 0: { case 0: {
this.center = new Point(); this.center = Point(0, 0);
this.radius = 0; this.radius = 0;
break; break;
} }