I'm translating some code developed in MATLAB to C++ using OpenCV. I'm loading an image in the RGB format like:
Mat img;
img = imread('path to directory', CV_LOAD_IMAGE_COLOR);
I just want to convert this image to double precision as im2double()
does it in MATLAB. Is there any function which allows to do it? Can I use the convertTo()
function?
I tried to do:
img.convertTo(img, CV_64FC3, 255.0);
But it's not working. Could you help me?
UPDATE: Thank you for your answers. What I'm doing now is something like
int i, k;
Mat img, img_dbprec;
img = imread('path to directory', CV_LOAD_IMAGE_COLOR); //Loads the image in the RGB format
img.convertTo(img_dbprec, CV_64FC3,1.0/255.0);//Convert image to double precision
for(i=0; i<img_dbprec.rows; i++){
for(k=0; k<img_dbprec.cols; k++){
cout << (double) img_dbprec.data[img_dbprec.step[0]*i + img_dbprec.step[1]* k + 0] << " ";
cout << (double) img_dbprec.data[img_dbprec.step[0]*i + img_dbprec.step[1]* k + 1] << " ";
cout << (double) img_dbprec.data[img_dbprec.step[0]*i + img_dbprec.step[1]* k + 2] << endl;
}
}
My output is (I will just put the final values):
...
150 150 150
21 21 21
85 85 85
214 213 213
22 22 22
22 22 22
214 213 213
85 85 85
21 21 21
which is not what I want. Can you tell me what I'm doing wrong?