Ask Your Question

Revision history [back]

OpenCV java reducing resolution of image

Hi,

I did lots of search around opencv forums around how to maintain priginal resolution in image, some people suggested to use "CV_LOAD_IMAGE_UNCHANGED" flag while imread operation before writing it, some forum answers says use PNG compression while writing it, none of those help really and I get output image with reduced resolution always.

Basically in java program I am just reading a jpg image using imread and then immediately writing it to disk using imwrite, and I get image same image on disk with reduced resolution. After trying lots of combinations I am about to give up and switch to some other library which can be used to read image, and process it and then store it at same resolution. But before switching to some other library I wanted to give final try by asking for any answer from experts here.

My current sample JAVA code is -

File imageFile= new File("jpgfilefromdisk.jpg);//read source file from disk
Mat original = Imgcodecs.imread(imageFile.getAbsolutePath(), Imgcodecs.CV_LOAD_IMAGE_UNCHANGED);
MatOfInt par = new MatOfInt(Imgcodecs.CV_IMWRITE_PNG_COMPRESSION, 3);
Imgcodecs.imwrite(new File("./outputdir").getAbsolutePath() + "/cvimage.jpg", mat, par);

When I read original image in photoshop, windows photo viewer etc, the original image is 300 dpi. But when I read same image which was written to disk from openCV (cvimage.jpg), I can see the dip is reduced to 75dpi by just reading and writing same file from opencv.

Appreciate comments from experts here.

Regards, Pras