perspectiveCorrection()
Transforms an image’s perspective.
Declaration
class func perspectiveCorrection() -> any CIFilter & CIPerspectiveCorrectionReturn Value
The adjusted image.
Discussion
This method applies the perspective correction filter to an image. The effect applies a perspective correction transforming nonrectangular area in the source image to a rectangular output image.
The perspective correction filter uses the following properties:
inputImageAn image with the type CIImage.
topLeftA CGPoint in the input image mapped to the top-left corner of the output image.
topRightA CGPoint in the input image mapped to the top-right corner of the output image.
bottomLeftA CGPoint in the input image mapped to the bottom-left corner of the output image.
bottomRightA CGPoint in the input image mapped to the bottom-right corner of the output image.
The following code creates a filter that corrects the perspective to appear straight:
func perspectiveCorrection(inputImage: CIImage) -> CIImage {
let perspectiveCorrectionFilter = CIFilter.perspectiveCorrection()
perspectiveCorrectionFilter.inputImage = inputImage
perspectiveCorrectionFilter.topRight = CGPoint(x: 0, y: 3024)
perspectiveCorrectionFilter.topLeft = CGPoint(x: 4032, y: 3024)
perspectiveCorrectionFilter.bottomRight = CGPoint(x: 200, y: 0)
perspectiveCorrectionFilter.bottomLeft = CGPoint(x: 4032, y: 0)
return perspectiveCorrectionFilter.outputImage!
}[Image]