I'm writing a feature for correcting perspective of documents scanned from ios camera.
I want to create a border effect around the document whose edge has been determined. CiImage has the initializer property with which i can create a color overlay over the detected edge. What i want to do is instead of creating colored area I want to create bordered area but in real time. What is the best way to do that?
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)
}