How to solve memory leak problem when using opencv.js?

asked 2020-11-15 23:49:30 -0600

pnbao gravatar image

I am using opencv.js to process images upload by user but met memory leak problem. I have tried the same code as opencv.js document but still met the problem.

Here is my code:

let land = window.cv.imread("land-show");
let mask = window.cv.imread("mask-show");
let sky = window.cv.imread("sky-show");

window.cv.threshold(mask, mask, parseFloat(trackBarValue), parseFloat(trackBarValue), window.cv.THRESH_TRUNC);

let mat = mask.clone();

window.cv.resize(sky, sky, land.size());
window.cv.resize(mask, mask, land.size());
sky.convertTo(sky, window.cv.CV_64FC4, 1);
mask.convertTo(mask, window.cv.CV_64FC4, 1 / 255);
land.convertTo(land, window.cv.CV_64FC4, 1);
sky = sky.mul(mask, 1);

window.cv.cvtColor(mat, mat, window.cv.COLOR_RGBA2RGB, 0);
window.cv.bitwise_not(mat, mat)
window.cv.cvtColor(mat, mat, window.cv.COLOR_RGB2RGBA, 0);
mat.convertTo(mat, window.cv.CV_64FC4, 1 / 255);

land = land.mul(mat, 1);
window.cv.add(land, sky, land);
land.convertTo(land, window.cv.CV_8UC4, 1);
window.cv.imshow("output", land);
land.delete();
mask.delete();
sky.delete();
mat.delete();
edit retag flag offensive close merge delete

Comments

use stack trace for idle process (i.e. weatherbug) in dev tool

kpachinger gravatar imagekpachinger ( 2020-11-16 03:09:53 -0600 )edit