Question

I have a 3x3 homography matrix , which I computed using findHomography() function. I store it in a cv::Mat matrix.

I am trying to do element access using the following code

float cvHomography::accessElements(const cv::Mat& aCvMat)
{
    //cout << aCvMat << endl;

    const float* Mi;
    for( int i = 0; i < aCvMat.rows; i++){
        Mi = aCvMat.ptr<float>(i);
        for( int j = 0; j < aCvMat.cols; j++){
            cout << Mi[j] << endl;
        }
    }
}

The above does not return the correct value from the homography matrix. I have searched through documentation , tutorials and google and I honestly cannot see what I am doing wrong.

Was it helpful?

Solution

This should work (if you are sure that type of the image is CV_64F):

void cvHomography::accessElements(const cv::Mat& aCvMat)
{
    // assert aCvMat.type() == CV_64F
    for( int i = 0; i < aCvMat.rows; i++){
        for( int j = 0; j < aCvMat.cols; j++){
            cout << aCvMat.at<double>(i,j) << endl;
        }
    }
}

Also an overloaded operator << for std::ostream works with cv::Mat if you would like just to display image elements.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top