justadudewhohacks / justadudewhohacks/opencv4nodejs

Possible memory leak

Open
#629 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
5.1k
Forks
826
PR merge metrics
No merged PRs in 30d

Description

I have a small image script that I build that returns cropped and modified versions of the original image. As far as I can tell I have a memory leak in regards to this function. It loops through a list of coords and creates crops. Adding some text in the bottom corner of some of the images.

```
const createCrops = path => async (
tempName,
fileName,
{ multi, count = 1 }
) => {
return new Promise((resolve, reject) => {
const mat = cv.imread(`${tempName}`);
const font = cv.FONT_HERSHEY_SIMPLEX;
const imageCoords = getImageCoords(mat.sizes);
const files = [];
const pathName = `${path}${fileName}-original.jpg`;
files.push({
key: 'original',
pathName,
name: `${fileName}-original.jpg`,
id: fileName,
});

if (multi) {
const fontScale = 4;
mat.putText(
String(count),
new cv.Point(100, 150),
cv.FONT_ITALIC,
fontScale,
{ color: green, thickness: 4 }
);
}
cv.imwrite(pathName, mat);
Object.entries(imageCoords)
.filter(([key]) => (multi ? key === 'front' || key === 'back' : key))
.forEach(([key, coords]) => {
const rect = mat.getRegion(new cv.Rect(...coords));

const alpha = 0.4;
if (multi) {
const fontScale = 4;
console.log(rect);
rect.putText(
String(count),
new cv.Point(rect.cols - 100, rect.rows - 100),
cv.FONT_ITALIC,
fontScale,
{ color: green, thickness: 4 }
);
}
const pathName = `${path}${fileName}-${key}.jpg`;
files.push({
key,
pathName,
name: `${fileName}-${key}.jpg`,
id: fileName,
});
cv.imwrite(pathName, rect);
});
resolve(files);
});
};

```
In any case the memory foot print goes up a few mb every time this function gets called. Any help at all would be appreciated thanks.

*OpenCV version* (example 3.4.1): Auto installed I wasn't sure how to find this

*OS*: Ubuntu

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.