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
Raster 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
-
Method Details
-
apply
public static Raster apply(Raster raster, double[] srcPoints, double[] dstPoints, int outputWidth, int outputHeight) Apply a perspective transform to aRasterfrom 4 source/destination point pairs. 通过 4 个源/目标点对对Raster应用透视变换。Output preserves the source pixel format. Out-of-bounds samples are transparent (alpha formats) or opaque black (non-alpha formats).
输出保留源像素格式。越界采样在含 alpha 的格式中为透明, 在非 alpha 格式中为不透明黑。
- Parameters:
raster- the source raster | 源 rastersrcPoints- source points [x0,y0, x1,y1, x2,y2, x3,y3] | 源点坐标dstPoints- destination points [x0,y0, x1,y1, x2,y2, x3,y3] | 目标点坐标outputWidth- the output raster width | 输出 raster 宽度outputHeight- the output raster height | 输出 raster 高度- Returns:
- the transformed raster (same format as source) | 变换后的 raster(与源格式相同)
- Throws:
NullPointerException- if any input is null | 任一输入为 null 时抛出ImageOperationException- if points length is wrong, dimensions are non-positive, or the homography is degenerate | 长度不对、尺寸非正或单应性退化时抛出- Since:
- opencode-base-image V1.0.4
-