3

我正在测试 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 数据集中获得合理的单应结果。

提前致谢,

4

1 回答 1

0

为了将来参考,我能够将 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 的转置。

于 2018-10-16T22:51:03.863 回答