OpenCV JPEG 12-bit support

asked 2012-08-08 07:14:00 -0600

Ilias gravatar image

updated 2012-08-08 07:39:19 -0600

sammy gravatar image

I am working on a project that requires processing grayscale JPEG images with 12-bit depth per pixel. Does OpenCV support 12-bit JPEG images?

The 3rd party library 'libjepg' used by OpenCV supports 12-bit JPEG's but needs to be built for 12-bit support. The macro that defines 8/12-bit support is BITS_IN_JSAMPLE in jmorecfg.h under opencv/3rdparty/libjepg.

If I change that macro to 12-bit and rebuild OpenCV, am I good to go? Or does this mess up the internals of OpenCV?

edit retag flag offensive close merge delete


Not exactly an answer, but did you try to load with CV_IMREAD_ANYDEPTH? Check this out

sammy gravatar imagesammy ( 2012-08-08 07:38:31 -0600 )edit

I shall try this thanks a lot.

However, my understanding is that I still need to recompile libjpeg for 12-bit support (as this library is in charge of encoding/decoding jpeg images).

I ll have a go and post back.

Ilias gravatar imageIlias ( 2012-08-08 08:01:10 -0600 )edit

Changed BITS_IN_JSAMPLE to 12 in jmorecfg.h but OpenCV won't build :-( There's type mismatches in grfmt_jpeg.cpp. OpenCV expects uchar but gets ushort instead. So looks like OpenCV does not take into account the BITS_IN_JSAMPLE macro to configure itself accordingly. Shame.

Would it be complete madness to attempt to fix this myself? The type errors seem to be located only in grfmt_jpeg.cpp and don't seem that hard to fix. I am a bit concerned though that any changes in here will cascade to the rest of the OpenCV library. Are there any gurus that know this part of the code? Any advice?

Ilias gravatar imageIlias ( 2012-08-08 09:57:31 -0600 )edit

Did you ever got this to work? I am trying to do the same thing and running into the exact same issue. Would appreciate any tips you have for me. Thanks

spacemanspiff0211 gravatar imagespacemanspiff0211 ( 2019-01-23 17:03:44 -0600 )edit