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?
Well surely it doesn't exist at present. Also, I think in the above code, in addition to scaling you are also moving the position of Rect.
I agree with him, you should keep the original 0,0 coordinates if you want a solution to your problem stated above.
Yes, that was intended, in fact I stated "relatively to axis origin (0,0)", because I am scaling the whole coordinate system because of a camera calibration factor (px/mm). If I wanted to scale the Rect relatively to its top-left corner I should have done as Steven suggested.