I have a camera with a double lens connected via USB to my computer and I have created an anaglyphic 3D video using OpenCV on Javascript.
The problem is, I reach an error called OutOfMemory. I have checked for leak memory from my variables that are in a loop and I could see that everyone remains with its same pointer, except one, here the code:
I had to debug and I realize that this variable changed its pointer every time the loop started again:
CorrIzq = dstIzq.roi(RectImgIzq);
So, I commented and I pass it directly on addWeighted()
function, but now it assigned a new pointer to dstEstereoscopico
(this is a variable Mat). So, I put it as const and seems it has the same pointer every loop, but still the memory overflow.
Can you help me, please?
Do you know if this could be a bug or maybe I'm using it wrong?
function processVideo() {
begin = Date.now();
try {
//dstEstereoscopico = new cv.Mat(videoEstereoscopico.height - 15, videoEstereoscopico.width - 20, cv.CV_8UC1);
console.log(dstEstereoscopico);
//Dibujando en el objeto Canvas
capIzq.read(srcIzq);
capDer.read(srcDer);
console.log(capIzq);
//Obteniendo canales RGB
cv.split(srcIzq, Array_rgbValores);
Array_rgbValores.set(1, cv.Mat.zeros(canvasFrameIzq.height, canvasFrameIzq.width, cv.CV_8UC1));
Array_rgbValores.set(2, cv.Mat.zeros(canvasFrameIzq.height, canvasFrameIzq.width, cv.CV_8UC1));
cv.cvtColor(srcIzq, dstIzq, cv.COLOR_RGBA2GRAY);
cv.merge(Array_rgbValores, dstIzq);
//Aplicando corrección de posicionamiento
//CorrIzq = dstIzq.roi(RectImgIzq);
//console.log(CorrIzq);
cv.split(srcDer, Array_rgbValores);
Array_rgbValores.set(0, cv.Mat.zeros(canvasFrameIzq.height, canvasFrameIzq.width, cv.CV_8UC1));
Array_rgbValores.set(1, cv.Mat.zeros(canvasFrameIzq.height, canvasFrameIzq.width, cv.CV_8UC1));
cv.cvtColor(srcDer, dstDer, cv.COLOR_RGBA2GRAY);
cv.merge(Array_rgbValores, dstDer);
//CorrDer = dstDer.roi(RectImgDer);
//corrDer = dstDer,
cv.addWeighted(dstIzq.roi(RectImgIzq), 0.7, dstDer.roi(RectImgDer), 0.5, 1, dstEstereoscopico);
contextDer.clearRect(0,0, canvasFrameDer.width, canvasFrameDer.height);
contextIzq.clearRect(0,0, canvasFrameIzq.width, canvasFrameIzq.height);
contextDestEste.clearRect(0,0, videoEstereoscopico.width, videoEstereoscopico.height);
cv.imshow("videoEstereoscopico", dstEstereoscopico);
// schedule next one.
/*srcIzq.delete();
srcDer.delete();
dstIzq.delete();
dstDer.delete();
Array_rgbValores.delete();*/
//dstEstereoscopico.delete();
//dstEstereoscopico = [];
//CorrIzq.delete();
//CorrDer.delete();
//console.log(performance.memory);
//console.log("El contador es: " + contador++);
//console.log("Tiempo transcurrido: " + (Date.now() - tiempoInicio)/1000 + " s");
clearTimeout(id_SetProVid);
delay = ((Date.now() - begin));
id_SetProVid = setTimeout(processVideo, delay);
} catch (err) {
console.log("El error se ha cacheado");
this.printError(err);
}
}
setTimeout(processVideo, 0);
};