【问题标题】:Where in the Source code for OpenCV is the Size Class?OpenCV 的源代码中的哪里是 Size Class?
【发布时间】:2014-03-19 09:27:26
【问题描述】:

我在 Opencv 目录中搜索了 Size:: CV_EXPORTS SIZE Size::width,但我只能找到模板类 Size_,与文档中的相同。我想查看源代码,因为我正在向 OpenCV 库添加改进,这些信息会很有用。在 Ubuntu Trusty 上,我像这样运行 grep:

grep -r 'CV_EXPORTS SIZE' . 

从根文件夹中的模块目录

提前感谢任何接受者。

【问题讨论】:

    标签: c++ c opencv


    【解决方案1】:

    哦,那是一棵很深的源代码树。无论如何,opencv/modules/core/include/opencv2/core/types.hpp 有:

    /*!
    The 2D size class
    
    The class represents the size of a 2D rectangle, image size, matrix size etc.
    Normally, cv::Size ~ cv::Size_<int> is used.
    */
    template<typename _Tp> class Size_
    {
     //! various constructors
        Size_();
        Size_(_Tp _width, _Tp _height);
        Size_(const Size_& sz);
        Size_(const Point_<_Tp>& pt);
    
        Size_& operator = (const Size_& sz);
        //! the area (width*height)
        _Tp area() const;
    
        //! conversion of another data type.
        template<typename _Tp2> operator Size_<_Tp2>() const;
    
        _Tp width, height; // the width and the height
    };
    
    /*!
    \typedef
    */
    typedef Size_<int> Size2i;
    typedef Size_<float> Size2f;
    typedef Size_<double> Size2d;
    typedef Size2i Size;
    

    所以,SizeSize2i 的别名,Size_&lt;int&gt; 是别名。

    【讨论】:

    • 非常感谢您为我解答这个问题,请问size的width对象是在哪里定义的,是Size_(_Tp _width, _Tp _height)
    • @user3411335 我怀疑你对模板不是很熟悉。您引用的代码意味着Size_() 构造函数接受两个_Tp 类型的参数,这是模板类型。 _width_height 只是构造函数参数的名称。
    • 我的意思是如果你调用Size sz = (Size(640, 480) 然后调用cout &lt;&lt; sz.width; 那个.width 对象在哪里定义,就像在CV_EXPORTS MAT 例如行对象被定义...
    • 现在我怀疑你对 C++ 不是很熟悉。 sz.width 访问sz 对象的width 成员,该对象的类型为Size。查看类声明,它声明了两个成员widthheight
    • 所以你说这就是在模板类中声明成员时的样子Size_(_Tp _width, _Tp _height)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多