человеческое тело контур заливки emgucv c # - PullRequest
0 голосов
/ 08 марта 2019

У меня есть следующий код:

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

...