opencv4nodejs icon indicating copy to clipboard operation
opencv4nodejs copied to clipboard

Set PNG compression level in imwrite

Open fk242 opened this issue 5 years ago • 4 comments

I was trying to set PNG compression level when writing image to a file with imwriteAsync, but haven't found a way to do it.

In Python, that would be:

cv2.imwrite(filename, img, [cv2.IMWRITE_PNG_COMPRESSION, 9])

Is it possible to set this option in opencv4nodejs? Thank you.

fk242 avatar Apr 19 '19 13:04 fk242

@fk242 thats how I do it:

const encodeParams = [cv.IMWRITE_PNG_COMPRESSION, quality]
const buffer = await cv.imencodeAsync('.png', mat, encodeParams)
fs.writeFileSync(filepath, buffer)

stoefln avatar Apr 21 '19 11:04 stoefln

That works, thank you!

fk242 avatar Apr 23 '19 19:04 fk242

Strangely, compression through imwrite doesn't work after the resize() method has been called on the image file. @stoefln solution works well in this case.

lemoun avatar Mar 14 '21 10:03 lemoun

Just noticed the same problem. Seems to be a bug.

stoefln avatar Apr 26 '22 14:04 stoefln