我正在测试 Apple 的 Vision Alignment API,并且对 VNHomographicImageRegistrationRequest 有疑问。有没有人让它工作?我可以从中得到 warpTransform,但我还没有看到一个有意义的矩阵,这意味着,我无法获得将图像扭曲回源图像的结果。我正在使用 Opencv warpPerspective 来处理翘曲。
我正在调用它来进行转换:
class func homography(_ cgImage0 : CGImage!, _ cgImage1 : CGImage!, _ orientation : CGImagePropertyOrientation, completion:(matrix_float3x3?)-> ())
{
let registrationSequenceReqHandler = VNSequenceRequestHandler()
let requestHomography = VNHomographicImageRegistrationRequest(targetedCGImage: cgImage1, orientation: orientation)
let requestTranslation = VNTranslationalImageRegistrationRequest(targetedCGImage: cgImage1, orientation: orientation)
do
{
try registrationSequenceReqHandler.perform([requestHomography, requestTranslation], on: cgImage0) //reference
if let resultH = requestHomography.results?.first as? VNImageHomographicAlignmentObservation
{
completion(resultH.warpTransform)
}
if let resultT = requestTranslation.results?.first as? VNImageTranslationAlignmentObservation
{
print ("translation : \(resultT.alignmentTransform.tx) : \(resultT.alignmentTransform.ty)")
}
}
catch
{
completion(nil)
print("bad")
}
}
这可以工作并输出一个单应矩阵,但它的结果与我在执行 SIFT + Opencv findHomography 时得到的结果大不相同(https://docs.opencv.org/3.0-beta/doc/tutorials/features2d/feature_homography/feature_homography。 html )
无论我的图像对如何,我都无法从 Apple Vision 数据集中获得合理的单应结果。
提前致谢,