matrix.at<int>(i,j) gives wrong output [closed]
I do not know where I did wrong: The result is totally wrong.
int main(int argc, char *argv[])
{
cv::Mat a(3,3,CV_32SC1);
a.at<int>(2,2)=5;
for(int i =0; i <a.rows; i++){
for(int j =0; j <a.cols;j++){
cout<<a.at<int>(i,j);
}
}
return 0;
}
Solution:
I forgot to init value for each entry.
Init a 3 by 3 signed int Mat with zero:
cv::Mat a(3,3,CV_32SC1, Scalar(0));
wrong , as in ?
(3x3 Mat, 8 elements are not initialized , only 1 is. so what ?)
(besides, your lack of output formatting will make it hard to spot anything, like
cout << anumber << " "
would make it more transparent)Puuhhh.. Yes, stupid questions.
waschbaer, maybe it's just bad code, not a stupid question.
maybe you can solve it on your own, and even write an answer to it ? (highly welcome !)
(believe it or not, you're not alone with the problem , and some writeup would help future users !)
Thank you berak, you are the most friendly person I meet ever in the open source community.