Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Scaling a Rect

Hi,

I was trying to scale a Rect relatively to axis origin (0,0) by a fixed factor, and I was expecting that this would work, for example:

float factor = 1.75f;
Rect originalRect(10, 15, 100, 200);
Rect scaledRect = originalRect * factor;

but the binary * operator is not defined for Rect and the compiler correctly reports an error.

I had to manually scale each coordinate:

Rect scaledRect;
scaledRect.x = originalRect.x * factor;
scaledRect.y = originalRect.y * factor;
scaledRect.width = originalRect.width * factor;
scaledRect.height = originalRect.height * factor;

which takes a lot more lines of code ;)

Is this simple addition to Rect class planned to be implemented in a future OpenCV version?