简体   繁体   English

openCV单应矩阵中的访问元素

[英]accessing element in an openCV homography matrix

I have a 3x3 homography matrix , which I computed using findHomography() function. 我有一个3x3单应性矩阵,该矩阵是使用findHomography()函数计算的。 I store it in a cv::Mat matrix. 我将其存储在cv :: Mat矩阵中。

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. 我已经搜索了文档,教程和google,但老实说我看不到我在做什么错。

This should work (if you are sure that type of the image is CV_64F): 这应该可以工作(如果您确定图像类型为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. 如果您只想显示图像元素,则std :: ostream的重载运算符<<也可与cv :: Mat一起使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM