为什么OpenCV中的DMatch是一个结构而不是一个类

Why is DMatch in OpenCV a struct and not a class

本文关键字:一个 结构 OpenCV 为什么 DMatch 中的      更新时间:2023-10-16

到目前为止,我在C++接口中看到的所有其他类型都是一个类。为什么这里的DMatch仍然被列为一个结构,而文档说它在这里是一个类:

匹配关键点描述符的类:查询描述符索引、列车描述符索引、火车图像索引和描述符之间的距离

或者对类的引用是不明确的。只是想了解OpenCV为什么还在其C++接口中使用structs。

同样在文件/opencv-master/modules/core/doc/basic_structures.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文档中。这里作为一个类如下。。。所以我就这么做。。。感谢在这方面的帮助

    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;
    };
相关文章: