Transform.java 文件源码

java
阅读 24 收藏 0 点赞 0 评论 0

项目:RobotIGS 作者:
/**
 * Scales an image to an approximate size. The scale will always be equal
 * on the x and y axis, regardless of the approxSize.
 *
 * @param img          The image
 * @param approxSize   The target size
 * @param maximize     If maximize is true, then if the approxSize aspect ratio
 *                     does not match the target, then the largest possible image
 *                     would be used. If false (default), the the smallest image
 *                     would be used.
 * @param integerScale If true (default), then only integer scale factors would be used.
 *                     Otherwise, any scale factor can be used.
 */
private static double makeScale(Mat img, Size approxSize, boolean maximize, boolean integerScale) {
    Size imageSize = img.size();
    double ratioWidth = approxSize.width / imageSize.width;
    double ratioHeight = approxSize.height / imageSize.height;
    double ratio = maximize ? Math.max(ratioWidth, ratioHeight) : Math.min(ratioWidth, ratioHeight);
    if (MathUtil.equal(ratio, 1))
        return 1;
    if (integerScale) {
        //The scale factor is always greater than 1
        double scale = (ratio < 1) ? 1 / ratio : ratio;
        //If you are actually increasing the size of the object, use ceiling()
        //Otherwise, use floor()
        scale = maximize ^ (ratio < 1) ? Math.ceil(scale) : Math.floor(scale);
        //Get the actual ratio again
        return (ratio < 1) ? 1 / scale : scale;
    } else {
        return ratio;
    }
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号