How to compress JP2 file with OpenCV [closed]

asked 2018-10-04 10:46:58 -0600

flavienb gravatar image

updated 2018-10-04 10:47:12 -0600

Hello,

I am forced to deal with JP2 images for this case.

Here is the process :

  • Original image : 59Ko.

  • Converting to JPG for doing OpenCV things faster : 32Ko.

  • Converting back to JP2 : 170Ko.

I "convert" using the cv2.imwrite function.

From here, how to compress with OpenCV this JP2 image ?

Thank you for your help.

edit retag flag offensive reopen merge delete

Closed for the following reason question is off-topic or not relevant by berak
close date 2018-10-06 03:44:48.938180

Comments

why use opencv for this ?

berak gravatar imageberak ( 2018-10-04 11:30:04 -0600 )edit

Because I use this tool and if it is possible, it's convenient to me. Anyway, if you have another tool, I take.

flavienb gravatar imageflavienb ( 2018-10-04 12:07:05 -0600 )edit

it's still unclear, what you're doing, and where the problem is. look at it again, please.

berak gravatar imageberak ( 2018-10-05 03:21:43 -0600 )edit

Unclear ? My question is "How to compress a JP2 image with OpenCV ?".

For example, using a JPG image, you can do : cv2.imwrite(path, img, [int(cv2.IMWRITE_JPEG_QUALITY), 80])

How to do it for a JP2 image ?

flavienb gravatar imageflavienb ( 2018-10-05 03:24:33 -0600 )edit

ah, so the compression params are the problem ?

quick glance at the src code shows -- it does not use any.

the IMWRITE_JPEG_XXXX flags are only used for .jpg not for .jp2.

in other words, you can write jp2 files, but there's no control about compression,chroma, or anything else.

would that answer it ?

berak gravatar imageberak ( 2018-10-05 03:25:31 -0600 )edit

I don't exactly know how compression for pictures work, especially concerning the JP2 format.

What I finally would like is just to reduce the final size of the picture.

flavienb gravatar imageflavienb ( 2018-10-05 03:27:57 -0600 )edit

So impossible to do that in OpenCV ?

Do you know any library in Python able to do that ?

flavienb gravatar imageflavienb ( 2018-10-05 03:32:55 -0600 )edit

sorry, i have no idea (maybe someone else).

we can help you with opencv problems, but not recommend arbitrary python libs.

berak gravatar imageberak ( 2018-10-05 03:35:40 -0600 )edit

Thank you for your help!

flavienb gravatar imageflavienb ( 2018-10-05 03:51:17 -0600 )edit