C# Emgu FindTransformECC 遇到NaN

C# Emgu FindTransformECC NaN encountered

我正在尝试在 emgu C# 中测试 FindTransformECC 函数。它基于这篇文章:a link

我的代码是:

    public static Mat AlignImage(Mat sourceimage, Mat template, int iterations, double eps, MotionType _motionType = MotionType.Euclidean)
    {
        float[,,] warp_matrix_temp = new float[2, 3, 1];
        float[,] warp_matrix = new float[2, 3];

        CvInvoke.CvtColor(sourceimage, sourceimage, ColorConversion.Bgr2Gray);
        CvInvoke.CvtColor(template, template, ColorConversion.Bgr2Gray);

        Image<Gray, float> wm = new Image<Gray, float>(new Size(2, 3));
        wm.Data = warp_matrix_temp;

        CvInvoke.FindTransformECC(template, sourceimage, wm, _motionType, new MCvTermCriteria(iterations, eps));

        warp_matrix_temp = wm.Data;

        return new Mat();
    }

函数未完成,因为 FindTransformECC return 错误:"Emgu.CV.Util.CvException: 'OpenCV: NaN encountered.'" 我没有找到合适的解决方案。输入图像没问题。我把它写到文件中以确保它。 我正在使用从 nuget 包安装的 Emgu.CV 3.4.1.2976。 有人可以帮我吗?我不知道应该是什么问题。 非常感谢。

露西

EMGU 开发人员找到了答案(我们在回购 here 的问题中进行了讨论)。 需要初始化 warp 数组中的值:

float[,,] warp_matrix_temp = new float[2, 3, 1] { { { 1 }, { 0 }, { 0 } }, { { 0 }, { 1 }, { 0 } } };

这将有助于 运行 正常运行。 我希望这对以后的其他人有所帮助。

露西