Example #1
0
        public override bool Do()
        {
            try
            {
                m_contours.Clear();

                FilterDrawMode DrawOn     = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                CenterDrawMode CenterMode = (CenterDrawMode)EnumPropertys["CenterMode"].Value;


                FilterDrawMode   BoundingRect      = (FilterDrawMode)EnumPropertys["BoundingRect"].Value;
                bool             bShowBoundingRect = BoundingRect == FilterDrawMode.Show;
                FillDrawModeEnum FillMode          = (FillDrawModeEnum)EnumPropertys["FillMode"].Value;
                bool             bFill             = FillMode != FillDrawModeEnum.None;


                MovingPredictType movingType = (MovingPredictType)EnumPropertys["MovingType"].Value;


                foreach (var src in Sources)
                {
                    IContourFilter searchFilter = src as IContourFilter;
                    if (searchFilter == null)
                    {
                        continue;
                    }
                    var outData     = src.GetOut();
                    var contourSrcs = searchFilter.GetResultContours();
                    for (int dataID = 0; dataID < outData.Count; dataID++)
                    {
                        var dst            = outData[dataID].Image.Clone();
                        var aroundContours = contourSrcs[dataID].GetAroundContours(CenterMode,
                                                                                   IntPropertys["HScale"].Value,
                                                                                   FloatPropertys["RScale"].Value,
                                                                                   movingType, IntPropertys["MovingRange"].Value
                                                                                   );
                        m_contours.Add(aroundContours);

                        if (DrawOn == FilterDrawMode.Show)
                        {
                            if (FillMode == FillDrawModeEnum.SourceMeanColor)
                            {
                                aroundContours.UpdateMainColorAsMeanOfMask(dst);
                            }

                            aroundContours.Draw(dst, bFill, bShowBoundingRect, CenterMode);
                        }

                        this.m_out.Add(new DataSrc(dst, outData[dataID].Info, false));
                    }
                }
            }
            catch (CvException ex)
            {
                return(false);
            }
            return(true);
        }
Example #2
0
        public override bool Do()
        {
            try
            {
                m_contours.Clear();

                FilterDrawMode DrawOn            = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                FilterDrawMode BoundingRect      = (FilterDrawMode)EnumPropertys["BoundingRect"].Value;
                bool           bShowBoundingRect = BoundingRect == FilterDrawMode.Show;

                Rectangle rect = new Rectangle(IntPropertys["X"].Value - IntPropertys["SizeX"].Value / 2,
                                               IntPropertys["Y"].Value - IntPropertys["SizeY"].Value / 2,
                                               IntPropertys["SizeX"].Value, IntPropertys["SizeY"].Value);


                foreach (var src in Sources)
                {
                    IContourFilter searchFilter = src as IContourFilter;
                    if (searchFilter == null)
                    {
                        continue;
                    }
                    var outData     = src.GetOut();
                    var contourSrcs = searchFilter.GetResultContours();
                    for (int dataID = 0; dataID < outData.Count; dataID++)
                    {
                        var dst            = outData[dataID].Image.Clone();
                        var insideContours = contourSrcs[dataID].GetInsideRectArea(rect);
                        m_contours.Add(insideContours);

                        if (DrawOn == FilterDrawMode.Show)
                        {
                            insideContours.Draw(dst, false, bShowBoundingRect, CenterDrawMode.BoundingRectCenter);
                            CvInvoke.Rectangle(dst, rect, new MCvScalar(255, 77, 34), 5);
                        }

                        this.m_out.Add(new DataSrc(dst, outData[dataID].Info, false));
                    }
                }
            }
            catch (CvException ex)
            {
                return(false);
            }
            return(true);
        }
        public override bool Do()
        {
            try
            {
                var bReqFullUpdate = !m_isSelfClearOut || (pixelSumResults.Count == 0);
                if (bReqFullUpdate)
                {
                    pixelSumResults.Clear();
                }

                FilterDrawMode drawMode = (FilterDrawMode)EnumPropertys["Draw"].Value;

                int listID = 0;
                for (int srcID = 0; srcID < Sources.Count; srcID++)
                {
                    var outDatas = Sources[srcID].GetOut();
                    for (int dataID = 0; dataID < outDatas.Count; dataID++)
                    {
                        if (bReqFullUpdate)
                        {
                            pixelSumResults.Add(OpenCVHelper.GetPixelSum(outDatas[dataID].Image));
                        }

                        if (drawMode == FilterDrawMode.Show)
                        {
                            double val  = pixelSumResults[listID];
                            Mat    copy = outDatas[dataID].Image.Clone();
                            CvInvoke.PutText(
                                copy,
                                "sum:" + val.ToString(),
                                new System.Drawing.Point(10, IntPropertys["y"].Value),
                                FontFace.HersheyComplex, 1.0, new Bgr(IntPropertys["r"].Value, IntPropertys["g"].Value, IntPropertys["b"].Value).MCvScalar);
                            this.m_out.Add(new DataSrc(copy, outDatas[dataID].Info, false));
                        }
                        else
                        {
                            this.m_out.Add(outDatas[dataID].Clone());
                        }

                        listID++;
                    }
                }
            } catch { return(false); }
            return(true);
        }
Example #4
0
        public override bool Do()
        {
            try
            {
                m_contours.Clear();

                FilterDrawMode DrawOn            = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                FilterDrawMode BoundingRect      = (FilterDrawMode)EnumPropertys["BoundingRect"].Value;
                bool           bShowBoundingRect = BoundingRect == FilterDrawMode.Show;

                foreach (var src in Sources)
                {
                    IContourFilter searchFilter = src as IContourFilter;
                    if (searchFilter == null)
                    {
                        continue;
                    }
                    var outData     = src.GetOut();
                    var contourSrcs = searchFilter.GetResultContours();
                    for (int dataID = 0; dataID < outData.Count; dataID++)
                    {
                        var dst = outData[dataID].Image.Clone();

                        var shiftContours = contourSrcs[dataID].Shift(IntPropertys["ShiftX"].Value,
                                                                      IntPropertys["ShiftY"].Value,
                                                                      outData[dataID].Image.Width, outData[dataID].Image.Height);

                        m_contours.Add(shiftContours);

                        if (DrawOn == FilterDrawMode.Show)
                        {
                            shiftContours.Draw(dst, false, bShowBoundingRect, CenterDrawMode.BoundingRectCenter);
                        }

                        this.m_out.Add(new DataSrc(dst, outData[dataID].Info, false));
                    }
                }
            }
            catch (CvException ex)
            {
                return(false);
            }
            return(true);
        }
Example #5
0
        public override bool Do()
        {
            try
            {
                m_rectangles.Clear();
                FilterDrawMode DrawOn = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                bool           bDraw  = DrawOn == FilterDrawMode.Show;

                int clVal     = IntPropertys["Color"].Value;
                var drawColor = new MCvScalar((clVal * 2) % 255, (clVal * 0.5) % 255, clVal);

                var CenterMode = (FilterLogicMode)EnumPropertys["PixelSumCenter"].Value;

                foreach (var src in Sources)
                {
                    foreach (var outData in src.GetOut())
                    {
                        Mat dst = outData.Image.Clone();

                        int xx = 0;
                        int yy = 0;

                        int ww = IntPropertys["width"].Value;
                        int hh = IntPropertys["height"].Value;

                        switch (CenterMode)
                        {
                        case FilterLogicMode.Off:
                            xx = IntPropertys["x"].Value;
                            yy = IntPropertys["y"].Value;
                            break;

                        case FilterLogicMode.On:
                            var pointCenter = OpenCVHelper.GetXYPixelSumCenter(outData.Image);
                            xx = pointCenter.X - ww / 2;
                            yy = pointCenter.Y - hh / 2;
                            break;
                        }

                        if (xx < 0)
                        {
                            xx = 0;
                        }

                        if (yy < 0)
                        {
                            yy = 0;
                        }

                        if (xx > outData.Image.Width)
                        {
                            xx = outData.Image.Width;
                        }

                        if (yy > outData.Image.Height)
                        {
                            xx = outData.Image.Height;
                        }

                        if ((ww + xx) > outData.Image.Width)
                        {
                            ww = outData.Image.Width - xx;
                        }

                        if ((hh + yy) > outData.Image.Height)
                        {
                            hh = outData.Image.Height - yy;
                        }

                        Rectangle rect = new Rectangle(xx, yy, ww, hh);

                        if (m_rectangles.Count == 0)
                        {
                            m_rectangles.Add(rect); // буду делать только один ректангл, на все GetOut's, тут множить смысла не даёю, да лишний CropRectFilter делает
                        }
                        if (bDraw)
                        {
                            CvInvoke.Rectangle(dst, rect, drawColor, 3);
                        }

                        this.m_out.Add(new DataSrc(dst, outData.Info, false));
                    }
                }
            }
            catch { return(false); }
            return(true);
        }
Example #6
0
        public override bool Do()
        {
            try
            {
                m_rectangles.Clear();
                FilterDrawMode DrawOn     = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                RectExportMode ExportMode = (RectExportMode)EnumPropertys["ExportMode"].Value;

                int drawSubID = 0;
                foreach (var src in Sources)
                {
                    var outData = src.GetOut();

                    IContourFilter contourFilter = src as IContourFilter;
                    if (contourFilter == null)
                    {
                        continue;
                    }

                    var contourOfImgs = contourFilter.GetResultContours();

                    for (int dataID = 0; dataID < outData.Count; dataID++)
                    {
                        switch (ExportMode)
                        {
                        case RectExportMode.ConcatenateBoundingCenterAbs:
                        case RectExportMode.ConcatenateeWeightCenterAbs:
                            m_rectangles.Add(
                                contourOfImgs[dataID].GeRectWithConcatenateCentert(IntPropertys["AbsWidth"].Value,
                                                                                   IntPropertys["AbsHeight"].Value,
                                                                                   ExportMode == RectExportMode.ConcatenateeWeightCenterAbs
                                                                                   ));
                            break;

                        case RectExportMode.EachBoundingCenterAbs:
                        case RectExportMode.EachWeightCenterAbs:
                            foreach (var rect in contourOfImgs[dataID].ExportRects(IntPropertys["AbsWidth"].Value,
                                                                                   IntPropertys["AbsHeight"].Value,
                                                                                   ExportMode == RectExportMode.EachWeightCenterAbs))
                            {
                                m_rectangles.Add(rect);
                            }
                            break;

                        case RectExportMode.EachBoundingCenterScale:
                            foreach (var rect in contourOfImgs[dataID].ExportBoundingRects(FloatPropertys["ScaleWidth"].Value, FloatPropertys["ScaleHeight"].Value))
                            {
                                m_rectangles.Add(rect);
                            }
                            break;
                        }



                        var dst = outData[dataID].Image.Clone();

                        if (DrawOn == FilterDrawMode.Show)
                        {
                            for (int rectID = drawSubID; rectID < m_rectangles.Count; rectID++)
                            {
                                MCvScalar color = new MCvScalar((rectID * 23) % 255, (rectID * 44) % 255, ((rectID + 33) * 4) % 255);
                                CvInvoke.Rectangle(dst, m_rectangles[rectID], color, 3);
                            }
                        }
                        drawSubID = m_rectangles.Count;

                        this.m_out.Add(new DataSrc(dst, outData[dataID].Info, false));
                    }
                }
            }
            catch (CvException ex)
            {
                return(false);
            }
            return(true);
        }
Example #7
0
        public override bool Do()
        {
            try
            {
                m_rectangles.Clear();
                FilterDrawMode DrawOn = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                bool           bDraw  = DrawOn == FilterDrawMode.Show;

                int clVal     = IntPropertys["Color"].Value;
                var drawColor = new MCvScalar((clVal * 2) % 255, (clVal * 0.5) % 255, clVal);


                BaseFilter drawSourceFilter = Graph.GetFilter(EnumPropertys["DrawSource"].Value);
                if (drawSourceFilter == null)
                {
                    return(false);
                }


                foreach (var src in Sources)
                {
                    IRectangleFilter rectFilter = src as IRectangleFilter;
                    if (rectFilter == null)
                    {
                        continue;
                    }

                    src.GetOut(); // нужно обновить принудительно


                    foreach (var outData in drawSourceFilter.GetOut())
                    {
                        foreach (var rct in rectFilter.GetResultRectangles())
                        {
                            Mat dst = outData.Image.Clone();
                            int xx  = rct.X + IntPropertys["ShiftX"].Value;
                            int yy  = rct.Y + IntPropertys["ShiftY"].Value;
                            int ww  = rct.Width;
                            int hh  = rct.Height;

                            if (xx > outData.Image.Width)
                            {
                                xx = outData.Image.Width;
                            }

                            if (yy > outData.Image.Height)
                            {
                                xx = outData.Image.Height;
                            }

                            if ((ww + xx) > outData.Image.Width)
                            {
                                ww = outData.Image.Width - xx;
                            }

                            if ((hh + yy) > outData.Image.Height)
                            {
                                hh = outData.Image.Height - yy;
                            }

                            Rectangle rect = new Rectangle(xx, yy, ww, hh);

                            if (m_rectangles.Count == 0)
                            {
                                m_rectangles.Add(rect); // буду делать только один ректангл, на все GetOut's, тут множить смысла не даёю, да лишний CropRectFilter делает
                            }
                            if (bDraw)
                            {
                                CvInvoke.Rectangle(dst, rect, drawColor, 3);
                            }

                            this.m_out.Add(new DataSrc(dst, outData.Info, false));
                        }
                    }
                }
            }
            catch { return(false); }
            return(true);
        }
Example #8
0
        public override bool Do()
        {
            try
            {
                m_contours.Clear();
                FilterDrawMode DrawOn            = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                FilterDrawMode BoundingRect      = (FilterDrawMode)EnumPropertys["BoundingRect"].Value;
                bool           bShowBoundingRect = BoundingRect == FilterDrawMode.Show;
                CenterDrawMode centerDrawMode    = (CenterDrawMode)EnumPropertys["CenterDrawMode"].Value;


                FillDrawModeEnum FillMode = (FillDrawModeEnum)EnumPropertys["FillMode"].Value;
                bool             bFill    = FillMode != FillDrawModeEnum.None;

                FilterDrawMode Histogram  = (FilterDrawMode)EnumPropertys["Histogram"].Value;
                bool           bHistogram = Histogram == FilterDrawMode.Show;

                SourceDrawModeEnum SourceMode = (SourceDrawModeEnum)EnumPropertys["SourceMode"].Value;

                BaseFilter     drawSourceFilter = Graph.GetFilter(EnumPropertys["DrawSource"].Value);
                List <DataSrc> drawDataSrcs     = null;
                int            drawDataCnt      = 0;
                if (drawSourceFilter != null)
                {
                    drawDataSrcs = drawSourceFilter.GetOut();
                    drawDataCnt  = drawDataSrcs.Count;
                }


                foreach (var src in Sources)
                {
                    var outData = src.GetOut();

                    int dataID     = 0; // перебор картинок в сорсе
                    int exsourceID = 0; // перебор картинок стороннего источника при DrawSourceMode

                    Mat currentImg = null;
                    while ((dataID < outData.Count) || ((SourceMode == SourceDrawModeEnum.DrawSource) && (exsourceID < drawDataCnt)))
                    {
                        string dataInfo = "unknow";
                        if (dataID < outData.Count)
                        {
                            dataInfo   = outData[dataID].Info;
                            currentImg = outData[dataID++].Image;
                        }

                        if (currentImg == null)
                        {
                            break;
                        }

                        Mat dst = null;
                        switch (SourceMode)
                        {
                        case SourceDrawModeEnum.Self: dst = currentImg.Clone(); break;

                        case SourceDrawModeEnum.None: dst = new Mat(currentImg.Size, currentImg.Depth, currentImg.NumberOfChannels); break;

                        case SourceDrawModeEnum.DrawSource:
                            if (exsourceID < drawDataCnt)
                            {
                                dataInfo = drawDataSrcs[exsourceID].Info;
                                dst      = drawDataSrcs[exsourceID++].Image.Clone();
                            }
                            else
                            {
                                dst = new Mat(currentImg.Size, currentImg.Depth, currentImg.NumberOfChannels);
                            }
                            break;
                        }

                        CvContours contours = new CvContours();
                        contours.Update(currentImg);

                        if (FillMode == FillDrawModeEnum.SourceMeanColor)
                        {
                            contours.UpdateMainColorAsMeanOfMask(dst);
                        }

                        if (centerDrawMode == CenterDrawMode.HistogramCenter)
                        {
                            contours.UpdateXYHistogram();
                        }

                        if (DrawOn == FilterDrawMode.Show)
                        {
                            contours.Draw(dst, bFill, bShowBoundingRect, centerDrawMode, IntPropertys["Thickness"].Value, bHistogram);
                        }

                        this.m_contours.Add(contours);
                        this.m_out.Add(new DataSrc(dst, dataInfo, false));
                    }
                }
            }
            catch (CvException ex)
            {
                return(false);
            }
            return(true);
        }
Example #9
0
        public override bool Do()
        {
            try
            {
                m_contours.Clear();

                FilterDrawMode DrawOn            = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                FilterDrawMode BoundingRect      = (FilterDrawMode)EnumPropertys["BoundingRect"].Value;
                bool           bShowBoundingRect = BoundingRect == FilterDrawMode.Show;

                FilterSelectMode SelectMode = (FilterSelectMode)EnumPropertys["SelectMode"].Value;
                Point            hearPoint  = new Point(IntPropertys["X"].Value, IntPropertys["Y"].Value);

                FillDrawModeEnum FillMode = (FillDrawModeEnum)EnumPropertys["FillMode"].Value;
                bool             bFill    = FillMode != FillDrawModeEnum.None;

                foreach (var src in Sources)
                {
                    IContourFilter searchFilter = src as IContourFilter;
                    if (searchFilter == null)
                    {
                        continue;
                    }
                    var outData     = src.GetOut();
                    var contourSrcs = searchFilter.GetResultContours();
                    for (int dataID = 0; dataID < outData.Count; dataID++)
                    {
                        var dst = outData[dataID].Image.Clone();

                        CvContours selContours = null;
                        switch (SelectMode)
                        {
                        case FilterSelectMode.MaxArea:
                            selContours = contourSrcs[dataID].GetMaxAreaContour(); break;

                        case FilterSelectMode.NearPointBR:
                            selContours = contourSrcs[dataID].GetNearPointContour(hearPoint, CenterDrawMode.BoundingRectCenter); break;

                        case FilterSelectMode.NearPointW:
                            selContours = contourSrcs[dataID].GetNearPointContour(hearPoint, CenterDrawMode.PixelWeightCenter); break;

                        case FilterSelectMode.NearPointH:
                            selContours = contourSrcs[dataID].GetNearPointContour(hearPoint, CenterDrawMode.HistogramCenter); break;
                        }


                        selContours.SetColor(new MCvScalar(IntPropertys["Blue"].Value, IntPropertys["Green"].Value, IntPropertys["Red"].Value));
                        m_contours.Add(selContours);


                        if (DrawOn == FilterDrawMode.Show)
                        {
                            if (SelectMode != FilterSelectMode.MaxArea)
                            {
                                Point ln11 = new Point(IntPropertys["X"].Value, 0);
                                Point ln12 = new Point(IntPropertys["X"].Value, dst.Height);

                                Point ln21 = new Point(0, IntPropertys["Y"].Value);
                                Point ln22 = new Point(dst.Width, IntPropertys["Y"].Value);
                                CvInvoke.Line(dst, ln11, ln12, new MCvScalar(255, 0, 0), 4);
                                CvInvoke.Line(dst, ln21, ln22, new MCvScalar(255, 0, 0), 4);
                            }

                            selContours.Draw(dst, bFill, bShowBoundingRect);
                        }

                        this.m_out.Add(new DataSrc(dst, outData[dataID].Info, false));
                    }
                }
            }
            catch (CvException ex)
            {
                return(false);
            }
            return(true);
        }
Example #10
0
        public override bool Do()
        {
            try
            {
                m_contours.Clear();
                FilterDrawMode   DrawOn            = (FilterDrawMode)EnumPropertys["DrawOn"].Value;
                FilterDrawMode   BoundingRect      = (FilterDrawMode)EnumPropertys["BoundingRect"].Value;
                bool             bShowBoundingRect = BoundingRect == FilterDrawMode.Show;
                CenterDrawMode   centerDrawMode    = (CenterDrawMode)EnumPropertys["CenterDrawMode"].Value;
                FillDrawModeEnum FillMode          = (FillDrawModeEnum)EnumPropertys["FillMode"].Value;
                bool             bFill             = FillMode != FillDrawModeEnum.None;

                FilterDrawMode Histogram  = (FilterDrawMode)EnumPropertys["Histogram"].Value;
                bool           bHistogram = Histogram == FilterDrawMode.Show;

                foreach (var src in Sources)
                {
                    IContourFilter searchFilter = src as IContourFilter;
                    if (searchFilter == null)
                    {
                        continue;
                    }

                    var outData     = src.GetOut();
                    var contourSrcs = searchFilter.GetResultContours();

                    for (int dataID = 0; dataID < outData.Count; dataID++)
                    {
                        var    dst      = outData[dataID].Image.Clone();
                        string dataInfo = outData[dataID].Info;

                        if (dataID >= contourSrcs.Count)
                        {
                            this.m_out.Add(new DataSrc(dst, dataInfo, false));
                            continue;
                        }

                        var sortAreaContour         = contourSrcs[dataID].GetPerimeterInRange(FloatPropertys["MinArea"].Value, FloatPropertys["MaxArea"].Value);
                        var sortPerimeterContour    = sortAreaContour.GetPerimeterInRange(FloatPropertys["MinPerimeter"].Value, FloatPropertys["MaxPerimeter"].Value);
                        var sortBoundingRectContour = sortPerimeterContour.GetBoundingRectInRange(IntPropertys["MinWidth"].Value, IntPropertys["MaxWidth"].Value,
                                                                                                  IntPropertys["MinHeight"].Value, IntPropertys["MaxHeight"].Value);

                        if (FillMode == FillDrawModeEnum.SourceMeanColor)
                        {
                            sortBoundingRectContour.UpdateMainColorAsMeanOfMask(dst);
                        }

                        m_contours.Add(sortBoundingRectContour);

                        if (centerDrawMode == CenterDrawMode.HistogramCenter)
                        {
                            sortBoundingRectContour.UpdateXYHistogram();
                        }

                        if (DrawOn == FilterDrawMode.Show)
                        {
                            sortBoundingRectContour.Draw(dst, bFill, bShowBoundingRect, centerDrawMode, IntPropertys["Thickness"].Value, bHistogram);
                        }

                        this.m_out.Add(new DataSrc(dst, dataInfo, false));
                    }
                }
            }
            catch (CvException ex)
            {
                return(false);
            }
            return(true);
        }