繁体   English   中英

OpenCV rect.width和rect.size()。width的区别?

[英]OpenCV rect.width and rect.size().width difference?

很抱歉提出一个菜鸟问题,但是有人可以告诉我这之间的区别吗

cv:: Rect rect;
int width = rect.width;
int height = rect.height;

和这个

cv::Rect rect;
int width = rect.size().width;
int height = rect.size().height;

它们是相同的, 没有区别


OpenCV是开源的,因此您可以随时查看源代码。

您可以看到widthheight是公共成员变量:

template<typename _Tp> class Rect_
{
public: 
    ...
    _Tp width; //!< width of the rectangle
    _Tp height; //!< height of the rectangle
};

size()返回一个用其值初始化的cv::Size

template<typename _Tp> inline
Size_<_Tp> Rect_<_Tp>::size() const
{
    return Size_<_Tp>(width, height);
}

显示的代码没有区别。
但是, widthheightRect 公共属性,如果更改它们,将更改Rect

size()仅返回Rect的大小(宽度,高度)。 您不能通过size()的成员更改Rect

暂无
暂无

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

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