Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change dpi of an image in OpenCV

Tags:

opencv

dpi

When I open an image in OpenCv (which may be of 300 dpi, 72 dpi etc.), the dpi of the image is automatically changed to 96 dpi. I want to variate this dpi. Please help. Thanks in advance...

#include "stdafx.h"
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <iostream>
using namespace std;
int _tmain(int argc, _TCHAR* argv[])
{
    IplImage *img1=cvLoadImage("input.jpg");
    cvSaveImage("output.jpg",img1);
    return(0);
}
like image 838
user1430186 Avatar asked Nov 03 '22 22:11

user1430186


2 Answers

OpenCV does not support meta-data mangling like this. You need to use another tool to re-set the DPI or consider incorporating libjpeg directly.

Another option is to take the OpenCV jpeg writer code and change it according to your needs.

like image 149
ypnos Avatar answered Nov 13 '22 04:11

ypnos


You need to edit the image meta data libexif(c) or exiv2 (c++)

like image 29
Martin Beckett Avatar answered Nov 13 '22 03:11

Martin Beckett