Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

matrix.at<int>(i,j) gives wrong output

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;
}

matrix.at<int>(i,j) gives wrong output

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);

matrix.at<int>(i,j) gives wrong output

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);
a(3,3,CV_32SC1, Scalar(0));