Ask Your Question
0

accessing element in a homography matrix

asked 2014-03-25 08:58:35 -0500

synthnassizer gravatar image

updated 2014-03-25 09:22:51 -0500

Hi all, 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.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2014-03-25 10:12:29 -0500

synthnassizer gravatar image

updated 2014-03-25 10:13:21 -0500

findHomography() returns a Matrix of <double> type elements, not <float>

edit flag offensive delete link more
1

answered 2014-03-25 09:25:17 -0500

berak gravatar image

updated 2014-03-25 10:15:54 -0500

use either:

for( int i=0; i<aCvMat.rows; i++){
    for( int j=0; j<aCvMat.cols; j++){
        cout << aCvMat.at<double>(i,j) << endl;
    }
}

or :

for( int i=0; i<aCvMat.rows; i++){
    const double* Mi = aCvMat.ptr<double>(i);
    for( int j=0; j<aCvMat.cols; j++){
        cout << Mi[j] << endl;
    }
}
edit flag offensive delete link more

Comments

@synthnassizer, thanks for reminding

berak gravatar imageberak ( 2014-03-25 10:17:11 -0500 )edit
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-03-25 08:58:35 -0500

Seen: 374 times

Last updated: Mar 25 '14