Class PerspectiveTransformOp
java.lang.Object
cloud.opencode.base.image.transform.PerspectiveTransformOp
Perspective (Homography) Transform Operations for Images
图像透视(单应性)变换操作
Applies perspective (projective) transformations to images using a homography matrix computed from 4 point correspondences via the Direct Linear Transform (DLT) algorithm. Unlike affine transforms, perspective transforms can model foreshortening and vanishing-point effects.
使用通过直接线性变换(DLT)算法从 4 个点对应关系计算的单应性矩阵,对图像进行透视(射影)变换。 与仿射变换不同,透视变换可以模拟透视缩短和消失点效果。
Features | 主要功能:
- 4-point perspective transform via DLT homography - 通过 DLT 单应性的 4 点透视变换
- Bilinear interpolation for sub-pixel accuracy - 双线性插值实现亚像素精度
- Document rectification (trapezoid to rectangle) - 文档矫正(梯形转矩形)
Usage Examples | 使用示例:
// Rectify a trapezoid region to a rectangle
double[] src = {50,50, 350,30, 380,280, 20,300}; // trapezoid corners
double[] dst = {0,0, 400,0, 400,300, 0,300}; // rectangle corners
BufferedImage rectified = PerspectiveTransformOp.apply(image, src, dst, 400, 300);
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是(无状态)
- Null-safe: No (validates input, throws on null) - 空值安全: 否(验证输入,null 时抛出异常)
- Since:
- JDK 25, opencode-base-image V2.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImageapply(BufferedImage image, double[] srcPoints, double[] dstPoints, int outputWidth, int outputHeight) Apply a perspective (homography) transform from 4 source points to 4 destination points.
-
Method Details
-
apply
public static BufferedImage apply(BufferedImage image, double[] srcPoints, double[] dstPoints, int outputWidth, int outputHeight) Apply a perspective (homography) transform from 4 source points to 4 destination points. 应用从 4 个源点到 4 个目标点的透视(单应性)变换。Points are specified as flat arrays: [x0, y0, x1, y1, x2, y2, x3, y3]. The homography is computed using the Direct Linear Transform (DLT) algorithm, then the inverse mapping is applied with bilinear interpolation.
- Parameters:
image- the source image | 源图像srcPoints- source points [x0,y0, x1,y1, x2,y2, x3,y3] | 源点坐标dstPoints- destination points [x0,y0, x1,y1, x2,y2, x3,y3] | 目标点坐标outputWidth- the output image width | 输出图像宽度outputHeight- the output image height | 输出图像高度- Returns:
- the transformed image | 变换后的图像
- Throws:
ImageOperationException- if any input is null, points arrays have wrong length, output dimensions are not positive, or the homography is degenerate 当输入为 null、点数组长度不对、输出尺寸非正数或单应性退化时抛出
-