[英]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是开源的,因此您可以随时查看源代码。
您可以看到width
和height
是公共成员变量:
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);
}
显示的代码没有区别。
但是, width
和height
是Rect
公共属性,如果更改它们,将更改Rect
。
size()
仅返回Rect
的大小(宽度,高度)。 您不能通过size()
的成员更改Rect
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.