c++ - 为什么 OpenCV 中的 DMatch 是结构体而不是类

标签 c++ c class opencv struct

到目前为止我所见过的 C++ 接口(interface)中的所有其他类型都是一个类。为什么是DMatch here当文档说它是一个类时,仍然被列为结构:

“匹配关键点描述符的类:查询描述符索引、训练描述符索引、训练图像索引和描述符之间的距离。”

或者对类的引用是否不明确。只是寻找有关 OpenCV 为何仍在其 C++ 接口(interface)中使用结构的信息。

也在文件/opencv-master/modules/core/doc/basic_structs.rst

DMatch 似乎被记录为一个类,例如

    DMatch
    ------
    .. ocv:class:: DMatch

    Class for matching keypoint descriptors: query descriptor index,
    train descriptor index, train image index, and distance between descriptors. ::

        class DMatch
        {
        public:
            DMatch() : queryIdx(-1), trainIdx(-1), imgIdx(-1),
                       distance(std::numeric_limits<float>::max()) {}
            DMatch( int _queryIdx, int _trainIdx, float _distance ) :
                    queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(-1),
                    distance(_distance) {}
            DMatch( int _queryIdx, int _trainIdx, int _imgIdx, float _distance ) :
                    queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(_imgIdx),
                    distance(_distance) {}

            int queryIdx; // query descriptor index
            int trainIdx; // train descriptor index
            int imgIdx;   // train image index

            float distance;

            // less is better
            bool operator<( const DMatch &m ) const;
        };

最佳答案

没关系,我发现它也列在 CORE 文档中。 here作为如下的一个类...所以我就这样...不过还是感谢您的帮助

    Never mind, I found it was also listed in the CORE doc. [here](http://docs.opencv.org/trunk/modules/core/doc/basic_structures.html?highlight=dmatch#DMatch) as a class...so I'm just going with that...Thanks for the help on this though
    DMatch

    class DMatch

    Class for matching keypoint descriptors: query descriptor index, train descriptor index, train image index, and distance between descriptors.

    class DMatch
    {
    public:
        DMatch() : queryIdx(-1), trainIdx(-1), imgIdx(-1),
                   distance(std::numeric_limits<float>::max()) {}
        DMatch( int _queryIdx, int _trainIdx, float _distance ) :
                queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(-1),
                distance(_distance) {}
        DMatch( int _queryIdx, int _trainIdx, int _imgIdx, float _distance ) :
                queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(_imgIdx),
                distance(_distance) {}

        int queryIdx; // query descriptor index
        int trainIdx; // train descriptor index
        int imgIdx;   // train image index

        float distance;

        // less is better
        bool operator<( const DMatch &m ) const;
    };

关于c++ - 为什么 OpenCV 中的 DMatch 是结构体而不是类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23354694/

相关文章:

c - c中整数到 float 的隐式转换

c# - 关于类的属性更改时如何使 UI 使用react的任何想法?

c++ - 为什么 std::vector 这么快(或者我的实现太慢了)

c++ - 键在 C++ 映射中不是唯一的

c - ruby 1.8 中缺少函数

javascript - 使用对象在 JavaScript 中添加多个 "public functions"

java - 当父类(super class)不存在时调用父类(super class)的构造函数

c++ - 在 Tic Tac Toe 程序中使用数组

c++ - 什么影响了我的指针集的排序(具体示例)

c - 将静态数组作为参数传递