Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Scale a RECT from its center ?

I have a

Rect ROI(tl,br);

Having for example scale = 0.5 How can I calc a new ROI that it's area is 0.5 of the original area while the center is the same?

I have wrote a function, I would like to know if there is a built in:

void scaleROI( Point2f& tl,Point2f& br, const Point2f& queryCenter, float scale  ) {


    //> TopLeft
    float shiftX = abs(queryCenter.x -tl.x);
    float shiftY = abs(queryCenter.y -tl.y);

    shiftX = shiftX * scale;
    shiftY = shiftY * scale;

    tl.x = queryCenter.x - shiftX;
    tl.y = shiftY + queryCenter.y;

    //> BottomRight

    shiftX = abs(br.x - queryCenter.x);
    shiftY = abs(br.y - queryCenter.y);

    shiftX = shiftX * scale;
    shiftY = shiftY * scale;

    br.x = queryCenter.x + shiftX;
    br.y = queryCenter.y - shiftY;



}

This calc a new topLeft and bottomRight point by scaling the shift between these points and the center.

Scale a RECT from its center ?

I have a

Rect ROI(tl,br);

Having for example scale = 0.5 How can I calc a new ROI that it's area is 0.5 of the original area while the center is the same?

I have wrote a function, I would like to know if there is a built in:function:

void scaleROI( Point2f& tl,Point2f& br, const Point2f& queryCenter, float scale  ) {


    //> TopLeft
    float shiftX = abs(queryCenter.x -tl.x);
    float shiftY = abs(queryCenter.y -tl.y);

    shiftX = shiftX * scale;
    shiftY = shiftY * scale;

    tl.x = queryCenter.x - shiftX;
    tl.y = shiftY + queryCenter.y;

    //> BottomRight

    shiftX = abs(br.x - queryCenter.x);
    shiftY = abs(br.y - queryCenter.y);

    shiftX = shiftX * scale;
    shiftY = shiftY * scale;

    br.x = queryCenter.x + shiftX;
    br.y = queryCenter.y - shiftY;



}

This calc a new topLeft and bottomRight point by scaling the shift between these points and the center.

I would like to know if there is a built in, or a better way to do it.

Sadly, ROI * scale isn't allowed