Ask Your Question

schmaedech's profile - activity

2014-07-20 17:13:57 -0500 answered a question How to resize boundingRect to fix size?

You need check the boundaries against the image:

        cv::Rect superbounds;
        superbounds.x = (int) (bounds.x - dst.cols / 6);
        superbounds.y = (int) (bounds.y - dst.rows / 6);
        superbounds.width = (int) (bounds.width + dst.cols / 3);
        superbounds.height = (int) (bounds.height + dst.rows / 3);

        superbounds.x = (superbounds.x > 0) ? superbounds.x : 0;
        superbounds.y = (superbounds.y > 0) ? superbounds.y : 0;
        superbounds.height = ((superbounds.height + superbounds.y) > dst.rows) ? (dst.rows - superbounds.y) : superbounds.height;
        superbounds.width = ((superbounds.width + superbounds.x) > dst.cols) ? (dst.cols - superbounds.x) : superbounds.width;