Ask Your Question

darryln's profile - activity

2014-07-15 01:45:57 -0500 received badge  Student (source)
2014-07-15 00:13:42 -0500 received badge  Supporter (source)
2014-07-15 00:09:25 -0500 answered a question using 3rd party jasper library fails in openCV 2.4.6 but works in 2.4.2

Hi gaurav_kl,

I am not sure if you have solved the problem or raised a ticket for it. I believe I have just asked a related question here.

I looks to be caused by 2012's commit to libjasper's jas_stream.c line 389 which has caused encoding to JPEG2000 to fail in Windows.

A few lines before that, tmpname() and open() opens up a temporary file but calling unlink() in windows when the file is opened will fail. I have resorted to reverting commit on 29/8/2012 to OpenCV's source master and build my own opencv_highguiXXX.dll which then allows me to call imencode or imwrite to JPEG2000 without failure.

If a ticket hasn't been raised, I hope this can help the dev people fix the issue in the new branch of OpenCV.

2014-07-15 00:02:25 -0500 received badge  Editor (source)
2014-07-14 23:58:27 -0500 asked a question 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 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.