当我使用 opencv.js 从 HTML 图像标签接收 mjpg 流时,Chrome 浏览器在一段时间后崩溃。
我想知道这是否是我造成的内存泄漏。我已经监控了 Windows 任务管理器(内存)并且 Chrome 进程内存爬了起来。
如果我注释掉特定的代码行,内存不会增加(但它不会做我想要的)。不知道如何构造代码。
HTML:(您必须获得自己的 opencv.js ..):
<html>
<head>
</head>
<body>
<div>Images</div>
<img id="image0" alt="No Image 0"/>
<img id="image1" alt="No Image 1"/>
<div>Output</div>
<canvas id="output0" width="640" height="360"></canvas>
<canvas id="output1" width="640" height="360"></canvas>
</body>
<script src="opencv.js"></script>
<script src="index.js"></script>
</html>
和 index.js:
'use strict';
const url0="http://10.0.0.58:8080/?action=stream";
const url1="http://10.0.0.58:8081/?action=stream";
image0.crossOrigin = "Anonymous";
image1.crossOrigin = "Anonymous";
let image0Loaded = false;
let image1Loaded = false;
const showImage0 = () => {
//orig had the 'cv' lines inside the setTimeout
// then realized it's the same thing.
// if i comment out the 'cv' code of course
// there's no increment in memory usage.
let mat = cv.imread(image0);
cv.imshow('output0',mat);
setTimeout(()=>{
showImage0();
}, 50);
}
const showImage1 = () => {
let mat = cv.imread(image1);
cv.imshow('output1',mat);
setTimeout(()=>{
showImage1();
}, 50);
}
function openCvReady() {
cv['onRuntimeInitialized']=()=>{
image0.onload = () => { showImage0(); }
image1.onload = () => { showImage1(); }
image0.src = url0;
image1.src = url1;
};
}
openCvReady();
我以前有