Ask Your Question
0

Converting CV::Mat to double *

asked Feb 8 '17

BhanuKiran gravatar image

Hi,

I am using C++ openCV-3.2.0 version.

I am also using a library for line segment detection,which takes only .pgm image of data type double *. I used

cv::Mat pgm_image;

pgm_image = cv::imread("image.pgm");

double *I = pgm_image.ptr<double>(0);

to read the image and to for getting pointer. And i tried parsing double * into the library that i am using. Is there any way around this? or Is there a way read .pgm file directly as double* ?

Preview: (hide)

Comments

i doubt, that there is double data inside your PGM file .

can you show the file header ?

head -c 200 image.pgm

(then add to your question)

berak gravatar imageberak (Feb 8 '17)edit
1

Hi, It looked like this

P2

820 615

255

188 188 188 190 .........

BhanuKiran gravatar imageBhanuKiran (Feb 8 '17)edit

1 answer

Sort by » oldest newest most voted
0

answered Feb 8 '17

berak gravatar image

updated Feb 8 '17

so, your file is in the "plain PGM" format, and contains single channel uchar data (not double).

to get a double *, you'll have to convert it:

Mat pgm_image = imread("image.pgm", IMREAD_GRAYSCALE); //flag is important !
Mat pgm_double;
pgm_image.convertTo(pgm_double, CV_64F); // optionally scale by 1.0/255, if you need [0..1] range
double *I = pgm_double.ptr<double>(0);
Preview: (hide)

Question Tools

1 follower

Stats

Asked: Feb 8 '17

Seen: 7,907 times

Last updated: Feb 08 '17