Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to get data of Mat?

I want to get data of Mat. I found many pages with info. But i still have questions.

http://jayrambhia.wordpress.com/2012/06/23/get-data-from-mat-cvmat-in-opencv/ http://docs.opencv.org/trunk/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html

I have it.

Mat lung_left( image_gray, Rect( 55, 100, 195, 290));
for( int i=0; i< lung_left.rows; i++){
    for( int j=0; j< lung_left.cols; j++){
       cout<<lung_left.at<float>(i,j)<<"\t";
    }
}

In console, i got it: 26e+008 -1598.2 -5.2332e-06 ...

but if use it: " lung_left.at<float>(i,j) = 0; " in the cycle and print, i got it: 0 0 0 0 ...

It's strange, i can change values using .at<>(i,j) but i can't print the values rightly.

click to hide/show revision 2
retagged

updated 2013-09-27 11:46:08 -0600

berak gravatar image

How to get data of Mat?

I want to get data of Mat. I found many pages with info. But i still have questions.

http://jayrambhia.wordpress.com/2012/06/23/get-data-from-mat-cvmat-in-opencv/ http://docs.opencv.org/trunk/doc/tutorials/core/how_to_scan_images/how_to_scan_images.html

I have it.

Mat lung_left( image_gray, Rect( 55, 100, 195, 290));
for( int i=0; i< lung_left.rows; i++){
    for( int j=0; j< lung_left.cols; j++){
       cout<<lung_left.at<float>(i,j)<<"\t";
    }
}

In console, i got it: 26e+008 -1598.2 -5.2332e-06 ...

but if use it: " lung_left.at<float>(i,j) = 0; " in the cycle and print, i got it: 0 0 0 0 ...

It's strange, i can change values using .at<>(i,j) but i can't print the values rightly.