Accessing a matrix element in the “Mat” object (not the CvMat object) in OpenCV C++

前端 未结 5 1018
有刺的猬
有刺的猬 2020-12-08 06:50

How to access elements by row, col in OpenCV 2.0\'s new \"Mat\" class? The documentation is linked below, but I have not been able to make any sense of it. http://opencv.wi

5条回答
  •  情歌与酒
    2020-12-08 07:40

    On the documentation:

    http://docs.opencv.org/2.4/modules/core/doc/basic_structures.html#mat

    It says:

    (...) if you know the matrix element type, e.g. it is float, then you can use at<>() method

    That is, you can use:

    Mat M(100, 100, CV_64F);
    cout << M.at(0,0);
    

    Maybe it is easier to use the Mat_ class. It is a template wrapper for Mat. Mat_ has the operator() overloaded in order to access the elements.

提交回复
热议问题