Ask Your Question
1

How to get data of Mat?

asked 2013-09-27 11:12:48 -0600

jecs89 gravatar image

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

berak gravatar image

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.

edit retag flag offensive close merge delete

Comments

2

you want lung_left.at<uchar>(i,j); here, not float

berak gravatar imageberak ( 2013-09-27 11:51:49 -0600 )edit

Thank you, i try it and worked. When i use uchar, i get char then i cast it in int.

I'm using it. unsigned char input = (unsigned char)(lung_left.data); and getting data in bucle with: (int)input[lung_left.step * j + i]

jecs89 gravatar imagejecs89 ( 2013-09-30 12:04:26 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
3

answered 2013-09-27 11:45:19 -0600

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

Your compiler is in debug mode.The issue is how to allocate the memory in debug mode that compiler fill it by specific pattern(magic debug values).If you build your code in the release mode probably the initial value is zero.Magic debug values are specific values written to memory during allocation or deallocation, so that it will later be possible to tell whether or not they have become corrupted, and to make it obvious when values taken from uninitialized memory are being used.

edit flag offensive delete link more

Comments

I got a bit. You can explain me more about how to make it. I'm using codeblocks. Thank you.

jecs89 gravatar imagejecs89 ( 2013-09-30 12:05:31 -0600 )edit

Question Tools

Stats

Asked: 2013-09-27 11:12:48 -0600

Seen: 1,628 times

Last updated: Sep 27 '13