从多个Emgu.Cv.Mat获取平均图像

时间:2018-11-20 16:09:01

标签: c# image emgucv

我必须使用Emgu.CV从一组图像中获取平均图像。输入图像为Image<Gray,byte> (1 channel, 1 byte pixels)。我已经编写了此方法,但无法正常工作:

public static Mat GetAverage(List<Mat> matrices)
{
    //where to store the result
    Mat result = new Mat(matrices.First().Size, 
                        DepthType.Cv16U, 
                        matrices.First().NumberOfChannels); 

    //where to store the partial sums
    using (Mat elementwiseSum = new Mat(matrices.First().Size, 
                                    DepthType.Cv64F, 
                                    matrices.First().NumberOfChannels)) 
    {
        // loop over the input
        foreach (Mat matrix in matrices)
        {
            // sum each image to the partial sum
            CvInvoke.Accumulate(matrix, elementwiseSum); 
        }
        // convert to UInt16 and scale by the number of input images
        elementwiseSum.ConvertTo(result, 
                                DepthType.Cv16U, 
                                1.0 / matrices.Count); 
    }
    return result;
}

elementwiseSumresult都缝成黑色图像...我在做什么错了?

0 个答案:

没有答案