コード例 #1
0
        /// <summary>
        /// Creates a new image that will be used as a mask for the histogram calculation.
        /// All forground points will be colored blue and all background points will be colored red.
        /// </summary>
        public static CVImage PrepareMask(CVImage image, Point[] forgroundPoints, Point[] backgroundPoints, bool includeNeautral, int floodFillThreshold)
        {
            CVImage outputImage = image.Clone();

            outputImage.Zero();

            FloodFillParams ffp = new FloodFillParams();

            ffp.Frame     = image;
            ffp.Threshold = floodFillThreshold;

            // fill all forground points in FG_COLOR
            foreach (Point pt in forgroundPoints)
            {
                RegionGrowing.Fill(pt, outputImage, new RegionGrowingCriteria(FloodFill), ffp, new LabelingFunc(RegionGrowing.DefaultLabeling), FG_COLOR);
            }

            // fill all background points in BG_COLOR
            foreach (Point pt in backgroundPoints)
            {
                RegionGrowing.Fill(pt, outputImage, new RegionGrowingCriteria(FloodFill), ffp, new LabelingFunc(RegionGrowing.DefaultLabeling), TEMP_BG_COLOR);
            }

            // now colorize to actual colors.
            for (int row = 0; row < outputImage.Height; ++row)
            {
                for (int col = 0; col < outputImage.Width; ++col)
                {
                    int argb = outputImage[row, col].ToColor().ToArgb();

                    if (includeNeautral)
                    {
                        if (argb == Color.Black.ToArgb())
                        {
                            outputImage[row, col] = new CVRgbPixel(NEAUTRAL_COLOR);
                        }
                    }

                    if (argb == TEMP_BG_COLOR.ToArgb())
                    {
                        outputImage[row, col] = new CVRgbPixel(BG_COLOR);
                    }
                }
            }

            // return as a grayscale image.
            CVImage grayscale = outputImage.ToGrayscale();

            outputImage.Release();
            return(grayscale);
        }
コード例 #2
0
        /// <summary>
        /// This callback is used in the call to RegionGrowing.Fill to perform
        /// flood fill.
        /// </summary>
        private static bool FloodFill(Point pt1, Point pt2, object cookie)
        {
            FloodFillParams ffp = cookie as FloodFillParams;

            return(RegionGrowing.FloodFillCondition(ffp.Frame, pt1, pt2, ffp.Threshold));
        }