I am writing a function to correct the perspective of documents scanned from an ios camera.
I want to create a border effect around a document whose border is defined. CiImage has an initializer property, with which I can create a color overlay on the detected edge. I want to do, instead of creating a color region, I want to create a boundary region, but in real time. What is the best way to do this?
fileprivate func overlayImageForFeatureInImage(_ image: CIImage, feature: CIRectangleFeature) -> CIImage! { var overlay = CIImage(color: CIColor(color: self.borderDetectionFrameColor)) overlay = overlay.cropping(to: image.extent) print("the extent of image is \(image.extent)") overlay = overlay.applyingFilter("CIPerspectiveTransformWithExtent", withInputParameters: ["inputExtent": CIVector(cgRect: image.extent), "inputTopLeft": CIVector(cgPoint: feature.topLeft), "inputTopRight": CIVector(cgPoint: feature.topRight), "inputBottomLeft": CIVector(cgPoint: feature.bottomLeft), "inputBottomRight": CIVector(cgPoint: feature.bottomRight)]) return overlay.compositingOverImage(image) }
source share