gpt4 book ai didi

ios - 新的 Apple Vision API VNTranslationalImageRegistrationRequest

转载 作者:搜寻专家 更新时间:2023-10-31 22:19:11 29 4
gpt4 key购买 nike

我正在尝试玩 Image Alignment Analysis新 Vision API 的一部分,但我正在为 VNTranslationalImageRegistrationRequest 的初始化而苦苦挣扎。我的代码如下:

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)
}

}
}
}

但在上面标记的行中,我不断收到以下错误,并且不确定如何修复它。 实例成员“sourceImage”不能用于类型“ImageTranslation”

谁能指出我正确的方向?谢谢

最佳答案

如何使用 VNTranslationalImageRegistrationRequest 的示例在两个图像上计算两个图像之间的平移:

import UIKit
import Vision

class ImageTranslation {

func translateImages(for referenceImage: UIImage,
floatingImage: UIImage,
completion: @escaping (_ alignmentTransform : CGAffineTransform?) -> Void) {
let translationRequest = VNTranslationalImageRegistrationRequest(targetedCGImage: floatingImage.cgImage!) { (request: VNRequest, error: Error?) in
completion((request.results?.first as? VNImageTranslationAlignmentObservation)?.alignmentTransform)
}
let vnImage = VNSequenceRequestHandler()
try? vnImage.perform([translationRequest], on: referenceImage.cgImage!)
}

}

关于ios - 新的 Apple Vision API VNTranslationalImageRegistrationRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44853490/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com