New Apple Vision API VNTranslationalImageRegistrationRequest

Viewed 1559

I am trying to play with the Image Alignment Analysis part of the new Vision API but i am struggling with the initialisation of VNTranslationalImageRegistrationRequest. My code is as follows:

import UIKit
import Vision

class ImageTranslation {

    var sourceImage: UIImage!

    lazy var imageTranslationRequest: VNTranslationalImageRegistrationRequest = {
//This line fails        let translationRequest = VNTranslationalImageRegistrationRequest(targetedCGImage: sourceImage.cgImage, completionHandler: self.handleImageTranslationRequest)

        return translationRequest
    }()

    func handleImageTranslationRequest(request: VNRequest, error: Error?) {

        guard let observations = request.results as? [VNImageTranslationAlignmentObservation]
            else { print("unexpected result type from VNDetectRectanglesRequest")
                return
        }
        guard observations.first != nil else {
            return
        }
        DispatchQueue.main.async {
            observations.forEach { observation in
                let transform = observation.alignmentTransform
                print(transform)
            }

        }
    }
}

But on the marked line above i keep getting the following error and am unsure how to fix it. Instance member 'sourceImage' cannot be used on type 'ImageTranslation'

Can anyone point me in the right direction? Thanks

1 Answers
Related