将Rect扩大100px [英] Expand Rect by 100px
问题描述
我在C ++中使用OpenCV 2.4.4,并让Rect我想按x像素放大. OpenCV文档提供了不错的示例(查找将矩形扩展或缩小一定数量" )如何在图片 http://opencv.willowgarage.com中使用/documentation/cpp/_images/math/a6f41031fb2ccaa600520bcbde63a8a9fcff9edf.png
I use OpenCV 2.4.4 in C++ and have Rect I want to make bigger by x pixels. OpenCV documentation provides nice example (look for "expanding or shrinking rectangle by a certain amount") how to use this in image http://opencv.willowgarage.com/documentation/cpp/_images/math/a6f41031fb2ccaa600520bcbde63a8a9fcff9edf.png
很酷.唯一的问题,我不知道如何在实际的C ++代码中输入此内容.我试过了:
Cool. Only problem I do not know how to enter this in actual C++ code. I tried:
Rect rect = oldrect + -10; Rect rect = oldrect- + 10; 和 Rect rect = oldrect±10; (我从 http://en.wikipedia.org/wiki/Plus-minus_sign确定.
Rect rect=oldrect+-10; Rect rect=oldrect-+10; and Rect rect=oldrect±10; (I copied this symbol from http://en.wikipedia.org/wiki/Plus-minus_sign to be sure.
我在其中任何一个上都有难看的错误.
I get ugly errors on any of them.
有人可以解释一下,我应该使用什么巧妙的符号,并且该符号不可能包含在HTML中,所以它作为图像嵌入了.
Can someone please explain, what is that clever symbol I should use and was impossible to include inside HTML, so it is embedded as image.
推荐答案
这是C ++中"+ ="的数学符号.您实际上并没有直接使用±.例如:
That's the mathematical notation for "+=" in C++. You don't actually use ± directly. For example:
//make a rectangle that's 10x10 and centered at (0, 0)
cv::Rect rect(0, 0, 10, 10);
std::cout << "Original Rectangle: " << rect.area() << std::endl;
//manual addition to rectangle dimensions -- this will make bigger_rect be 20x20
cv::Rect bigger_rect = rect;
bigger_rect.height += 10;
bigger_rect.width += 10;
std::cout << "Bigger Rectangle: " << bigger_rect.area() << std::endl;
//other method of adding to a rectangle's area -- this will increase rect to be 20x20
rect += cv::Size(10, 10);
std::cout << rect.area() << std::endl;
因此,以在矩形的高度和宽度上加10的示例为例,认为±
符号等效于+= cv::Size(width, height)
So to do your example of adding 10 to the height and width of a rectangle, think of the ±
symbol as being equivalent to += cv::Size(width, height)
好吧,您或多或少都有正确的主意...
Well, you more or less had the right idea...
关于您的评论,我应该详细说明: rect + =点,rect-=点,rect + =大小,rect-=大小是4个不同的操作,例如:
In regards to your comment, I should elaborate: rect += point, rect -= point, rect += size, rect -= size are 4 distinct operations, such that:
rect += point
和rect -= point
:逐点移动矩形,其中point指向cv::Point
对象,即您可以将点声明为:
cv::Point pt(5, 5);
,那么如果您执行rect += pt
,它将把矩形的x和y成员(默认情况下,指的是矩形的左上坐标)偏移5-例如.等同于执行rect.x += 5
和rect.y += 5
. rect -= point
的情况相同,只是减法而不是加法(所以rect.x -= 5
和rect.y -= 5
).
rect += point
and rect -= point
: shifts the rectangle by point, where point refers to a cv::Point
object, i.e. you can declare a point as:
cv::Point pt(5, 5);
, then if you do rect += pt
, it'll shift the rectangle's x and y members (by default, these refer to the rectangle's upper left coordinate) by 5 -- e.g. it's equivalent to doing rect.x += 5
and rect.y += 5
. The case for rect -= point
is the same, albeit for subtraction rather than addition (so rect.x -= 5
and rect.y -= 5
).
rect += size
和rect -= size
将更改矩形的大小,而不是其坐标位置,从而+=
将增加矩形区域,而-=
将减小矩形区域.
rect += size
and rect -= size
will change the rectangle's size as opposed to it's coordinate position, such that +=
will increase the rectangle area and -=
will decrease it.
这篇关于将Rect扩大100px的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!