我正在测试 Apple 的 Vision Alignment API,并对 VNHomgraphicImageRegistrationRequest 有疑问。有人让它工作吗?我可以从中得到 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 https://docs.opencv.org/3.0-beta/doc/tutorials/features2d/feature_homography/feature_homography.html)
无论我的图像对如何,我都无法从 Apple Vision 数据集中获得合理的单应性结果。
提前致谢,
为了将来的参考,我能够将 Apple 的单应性矩阵与 Opencv 的矩阵相关联。基本上,核心图像的图像原点是图像的左下角。 Opencv的原点是左上角。要将 Core Image 的单应性矩阵转换为 Opencv 坐标,需要应用以下变换:
H_opencv = Q * H_core_image * Q
where Q = [1 0 0; 0 -1 image.height; 0 0 1]
更新注意:
我将 Q 定义为行主矩阵。
Apple 的 simd 矩阵是列优先的。 Opencv 的矩阵是行优先的。为了使上面的方程起作用,您可能必须使用 Q 的转置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)