示例#1
0
        // Get area of similarly-colored pixels, starting from a point
        // Actually uses the FloodFill method but since this took me some time to figure out how it works, I have "libraried" the code
        // Note : uses 8-way filling, one may want to alter this...
        // =>	mask is input/output CvMat and has several restrictions; if you intend to use it on successive calls, pass it as null on first call
        //		and the function will create it for you appropriately.
        static public CvConnectedComp GetAreaOfSimilarPixels(CvMat input, CvPoint startPoint, CvScalar lower, CvScalar upper, ref CvMat mask, byte maskCol = 255)
        {
            CvConnectedComp filledAreaData;

            if (mask == null)
            {
                mask = new CvMat(input.Rows + 2, input.Cols + 2, MatrixType.U8C1, new CvScalar(0, 0, 0, 0));
            }

            input.FloodFill(
                startPoint, 0, lower, upper, out filledAreaData,
                (FloodFillFlag.Link8 | FloodFillFlag.MaskOnly | FloodFillFlag.FixedRange) + (maskCol << 8), mask);

            return(filledAreaData);
        }