Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

OpenCV 3rdparty libjasper causes failure in imencode / imwrite to JPEG2000

When using imencode or imwrite with extension ".jp2", error below is always thrown: Error = ......\modules\highgui\src\loadsave.cpp:440: error: (-215) code in function cv::imencode

This is performed on Windows OS 32-bit and 64-bit.

Digging deeper finds that jas_stream.c's jas_stream_tmpfile() returns 0 due to unlink() unsuccessful.

Looking through the source for libjasper (latest 1.900.1-13) shows that the commit for Debian bug at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=501021 has removed the comment before the call to "unlink()" that Windows will fail to unlink if file is already opened, and with that, a flag is set to unlink later.

With that reverted and a new opencv_highgui249d.dll built, I managed to encode to JPEG2000 into a file / memory by calling imencode or imwrite.

OpenCV's master source has the same code in that region.

I am not sure if this is a bug introduced for Windows in specific, or if I am calling opencv's code wrong. Please advice.

Thanks in advance.

OpenCV 3rdparty libjasper causes failure in imencode / imwrite to JPEG2000

When using imencode or imwrite with extension ".jp2", error below is always thrown: Error = ......\modules\highgui\src\loadsave.cpp:440: error: (-215) code in function cv::imencode

This is performed on Windows OS 32-bit and 64-bit.

Digging deeper finds that jas_stream.c's jas_stream_tmpfile() returns 0 due to unlink() unsuccessful.

Looking through the source for libjasper (latest 1.900.1-13) shows that the commit for Debian bug at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=501021 has removed the comment before the call to "unlink()" that Windows will fail to unlink if file is already opened, and with that, a flag is set to unlink later.

source: https://github.com/Itseez/opencv/blob/master/3rdparty/libjasper/jas_stream.c#L390

With that reverted and a new opencv_highgui249d.dll built, I managed to encode to JPEG2000 into a file / memory by calling imencode or imwrite.

OpenCV's master source has the same code in that region.

I am not sure if this is a bug introduced for Windows in specific, or if I am calling opencv's code wrong. Please advice.

Thanks in advance.