ios – How to draw on UIView from UIImage using Vision framework?



I am experimenting with how to use the Apple Version framework. I created contoured Detection using this tutorial. can I use the points from the version detection to draw lines or shapes on UIView using Core Graphic? I want the drawContours to return a UIView instead of UIImage

public func drawContours(contoursObservation: VNContoursObservation, sourceImage: CGImage) -> UIView {
        let size = CGSize(width: sourceImage.width, height: sourceImage.height)
        let renderer = UIGraphicsImageRenderer(size: size)
        let renderedImage = renderer.image { (context) in
        let renderingContext = context.cgContext

        let flipVertical = CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: size.height)

        renderingContext.draw(sourceImage, in: CGRect(x: 0, y: 0, width: size.width, height: size.height))
        renderingContext.scaleBy(x: size.width, y: size.height)
        renderingContext.setLineWidth(5.0 / CGFloat(size.width))
        let redUIColor =
        return renderedImage