Ask Your Question
1

how to obtain an address of image in memory

asked 2014-02-20 07:36:49 -0600

shiv.butekar gravatar image

updated 2014-02-20 07:38:02 -0600

I am having a object of image declared as Mat img; now how to get the address of zeroth row and zeroth column in memory

in what datatype it will be? how many bytes it takes to store value in one single cell of matrix?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-02-20 08:43:01 -0600

You can directly access data at the address Mat::datastart

You should read that : http://docs.opencv.org/modules/core/doc/basic_structures.html?highlight=datastart#mat

For an image, data is stored row by row. You should also consider using Mat::at<type>(y,x).

edit flag offensive delete link more
0

answered 2014-02-20 08:49:49 -0600

updated 2014-02-20 08:51:32 -0600

Every Mat object has an pointer to its data, for example with Mat img; the data pointer is img.data. Based on your image type (when declaring or reading from image file), that pointer can be casted to unsigned char * (for CV_8U or CV_8UC1, grayscale image and other CV_8Uxx), float * (for CV_32F and other CV_32FCxx), double * (for CV_64F or other CV_64Fxx). Based on your image datatype, you will know how many bytes it needs to store a single cell.

edit flag offensive delete link more

Comments

let us take image is CV_32F Mat img; float * data ; data= ??? i want to access value in the first cell of a matrix how to do that

shiv.butekar gravatar imageshiv.butekar ( 2014-02-20 10:08:22 -0600 )edit

Mat img; ... <do some works with img> float * pImg = (float*)img.data;

then pImg[0] is the first cell, the first row will end at pImg[img.cols-1]. You can access all cells with indexes range from 0 to (img.rows*img.cols)-1. Please mark your question as answered when you find what you want.

tuannhtn gravatar imagetuannhtn ( 2014-02-20 10:23:24 -0600 )edit

Question Tools

Stats

Asked: 2014-02-20 07:36:49 -0600

Seen: 1,153 times

Last updated: Feb 20 '14