人体轮廓溢洪道emgucv c#

时间:2019-03-08 20:57:28

标签: c# image-processing emgucv contour

我有以下代码:

public static Image<Gray, byte> Segmentation(Image<Gray, byte> Image)
    {
        Image<Gray, byte> Image2 = new Image<Gray, byte>(Image.Size);
        Image2 = Image.Clone();

        Image<Gray, float> edges = new Image<Gray, float>(Image2.Size);
        VectorOfVectorOfPoint contours = new VectorOfVectorOfPoint();
        Image<Gray, float> hierarchy = new Image<Gray, float>(Image2.Size);
        Image<Gray, byte> ContourImage = new Image<Gray, byte>(Image2.Size);

        CvInvoke.Canny(Image2, edges, 100, 200);
        CvInvoke.FindContours(edges, contours, hierarchy, RetrType.Tree, ChainApproxMethod.ChainApproxNone);
        CvInvoke.DrawContours(ContourImage, contours, -1, new MCvScalar(255, 255, 255), 1, LineType.EightConnected);

        MCvMoments moments = CvInvoke.Moments(ContourImage);
        Point WeightedCentroid = new Point((int)(moments.M10 / moments.M00), (int)(moments.M01 / moments.M00));
        ContourImage.Data[WeightedCentroid.Y, WeightedCentroid.X, 0] = 255;

        CvInvoke.Imshow("Contour", ContourImage);

        int height = ContourImage.Rows;
        int width = ContourImage.Cols;
        Mat outputMask = new Mat(height + 2, width + 2, DepthType.Cv8U, 1);
        Rectangle dummy = new Rectangle();
        CvInvoke.FloodFill(ContourImage, outputMask, WeightedCentroid, new MCvScalar(255), out dummy,
                           new MCvScalar(0), new MCvScalar(0), Connectivity.EightConnected, FloodFillType.MaskOnly);

        CvInvoke.Imshow("Contour", ContourImage);

        Image<Gray, byte> Image3 = new Image<Gray, byte>(ContourImage.Size.Width, ContourImage.Size.Height, new Gray(0));

        return Image3;
    }

上面的代码应该检测人体轮廓,计算中心点,然后用白色填充它,但是轮廓没有按预期填充。请问我的代码有什么问题?

图像轮廓 enter image description here

0 个答案:

没有答案