Ask Your Question
0

Converting CV::Mat to double *

asked 2017-02-07 22:41:11 -0600

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* ?

edit retag flag offensive close merge delete

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 ( 2017-02-08 00:58:42 -0600 )edit
1

Hi, It looked like this

P2

820 615

255

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

BhanuKiran gravatar imageBhanuKiran ( 2017-02-08 01:04:28 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-02-08 01:19:41 -0600

berak gravatar image

updated 2017-02-08 01:20:21 -0600

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);
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-02-07 22:41:11 -0600

Seen: 7,651 times

Last updated: Feb 08 '17