简体   繁体   English

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

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

Sorry for a noob question, but can somebody tell me the difference between this 很抱歉提出一个菜鸟问题,但是有人可以告诉我这之间的区别吗

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

and this 和这个

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

They are the same, NO difference . 它们是相同的, 没有区别


OpenCV is open source, so you can always look at the source code. OpenCV是开源的,因此您可以随时查看源代码。

You can see that width and height are public member variables: 您可以看到widthheight是公共成员变量:

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

and size() returns a cv::Size initialized with their values: size()返回一个用其值初始化的cv::Size

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

There is no difference with respect to the code you have shown. 显示的代码没有区别。
However, width and height are public attributes of Rect and if you change them you will be changing Rect . 但是, widthheightRect 公共属性,如果更改它们,将更改Rect

size() just returns the size (width, height) of Rect . size()仅返回Rect的大小(宽度,高度)。 You cannot change Rect through the members of size() . 您不能通过size()的成员更改Rect

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

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