Ask Your Question
0

mat output different in different data type

asked 2017-08-12 03:40:47 -0600

lyw8120 gravatar image

updated 2017-08-12 03:41:45 -0600

I am confusing on the output of Mat. I tried to print the elements on the terminal using different data type, but result vary.

this is code

        Mat rowMean;
    rowMean = Mat::zeros(1, 10, CV_32F);


    for (int i=0; i<rowMean.cols; i++)
    {
            std::cout<<rowMean.at<int>(1,i)<<" ";
    }
    std::cout << std::endl;

    std::cout<<rowMean<<std::endl;

while the result is vary

65 0 1956498344 32527 1956498344 32527 0 0 0 0 
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

that is interesting, could anyone tell me what is going on? thank you.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-08-12 03:48:17 -0600

berak gravatar image

you're "one-off" here, simply. if your Mat has a single row, the only valid row-index is 0 .

for (int i=0; i<rowMean.cols; i++)
{
        std::cout<<rowMean.at<int>(0,i)<<" ";
}

will give the correct result.

edit flag offensive delete link more

Comments

I am too stupid.

lyw8120 gravatar imagelyw8120 ( 2017-08-12 03:59:21 -0600 )edit
1

^^ well, take it more as an argument against writing "per-pixel" loops like that, in general.

berak gravatar imageberak ( 2017-08-12 04:31:36 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-12 03:40:47 -0600

Seen: 262 times

Last updated: Aug 12 '17