Ask Your Question

Does OpenCV support advanced libjpeg loading options?

asked 2014-10-09 14:16:10 -0500

rwong gravatar image

updated 2014-10-09 15:34:59 -0500

Some Android devices have small memory sizes, or implement very stringent memory usage policies.

For my Android image processing application, there are two JPEG-specific image decoding options that are available from libjpeg, which I would like to use through OpenCV's highgui module.

  1. To find out the size and pixel format of the JPEG file, without loading the pixels into memory.
  2. To decode the JPEG file with a power-of-two scale down factor, such that it is not necessary to allocate a matrix at the original dimensions. Instead, the matrix only needs to be allocated at the scaled-down dimensions.
  3. To optionally decode a color JPEG file in grayscale, such that one only needs to allocate a single-channel matrix, instead of a 8UC3 or 8UC4 matrix.

My question is:

  1. Does OpenCV support, or have plans to support such functionality?
  2. Has anyone done this with OpenCV before?

The image sizes will depend on the camera resolution. On some higher-end models, the image size can be in 10 - 20 megapixels. The allowed memory budget is 128 megapixels. This low memory budget is necessary because on a typical mobile device, a lot of background applications will be running, and it is deemed not acceptable (for a consumer-grade application, not for leisure) to kill or recycle other background applications to make more memory available.

I can program to libjpeg directly. I find the libjpeg static library in the OpenCV4Android package at "sdk/native/3rdparty/libs/arch". However, there is no corresponding header file of the libjpeg inside the OpenCV4Android package.

Linking to a second copy of libjpeg from my code is not an option due to multiple definitions.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2015-06-22 19:12:00 -0500

updated 2015-06-27 09:50:40 -0500

i want to share my way to use libjpeg loading options. here my addition to source

by this change i can set "scale_denom" parameter and load jpeg images scaled 1/2 - 1/4 - 1/8

also i wonder if it worth to merge to opencv library after revised by an opencv guru. any comment is welcome

edit flag offensive delete link more

Question Tools


Asked: 2014-10-09 14:16:10 -0500

Seen: 4,112 times

Last updated: Jun 27 '15