I have a simple struct to represent a percentage from left, top, right, bottom of an image to use for cropping:

```
struct RoiRect {
    unsigned int left;
    unsigned int top;
    unsigned int right;
    unsigned int bottom;

    bool isAllZero() {
        return left == 0 && top == 0 && left == 0 && bottom == 0;
    }

    void getCvRect(cv::Size cvSize, cv::Rect &cvRect) {
            int height = cvSize.height;
            int width = cvSize.width;

            int x = ((double)(left/height)*100);
            int y = ((double)(top/height)*100);
            int w = width - ((double)(right/width)*100);
            int h = height - ((double)(bottom/width)*100);

            cvRect.x = x;
            cvRect.y = y;
            cvRect.width = w;
            cvRect.height = h;
    }
};

```

I initialize this struct with values like 10,15,20,25. This means that an image should be cropped by 10% from its right side, 15% from its top and so on.

In another class I will call the `getCvRect` of the struct and pass in size of an image and also a raw `cv::Rect` object so the above function calculate the percentages and return a rectangle to be cropped from image:

```
//inside another function
cv::Rect rect; //rect to be calculated by getCvRect function of the struct
bool crop; //should crop or not? if all == zero then NOT!
if(!mRoiRect.isAllZero()) {
    crop = true;
    mRoiRect.getCvRect(mat.size(), rect);
}

```

But all the effort is in vain! I pass in a size as the first argument and I am pretty sure that the image size is e.g. 640x480...the `rect` object after the function call shows `640x480` ...so my function does absolutly nothing.

What am I doing wrong, and what can I do to fix or better what is the smarter way of doing this task?

**The correct implementation would be (for anyone interested)**

```
    int x = ((double) left / 100) * width;
    int y = ((double) top / 100) * height;
    int w = width - ((double) right / 100) * width;
    int h = height - ((double) bottom / 100) * width;

```