コード例 #1
0
        public override bool Do()
        {
            try
            {
                BaseFilter FromSource = Graph.GetFilter(EnumPropertys["FromSource"].Value);

                IContourFilter contourFilter = FromSource as IContourFilter;
                if (contourFilter != null)
                {
                    m_contours = contourFilter.GetResultContours();
                }
                else
                {
                    m_contours = new List <CvContours>();
                }


                IRectangleFilter rectFilter = FromSource as IRectangleFilter;
                if (rectFilter != null)
                {
                    m_rectangles = rectFilter.GetResultRectangles();
                }
                else
                {
                    m_rectangles = new List <Rectangle>();
                }

                foreach (var outData in FromSource.GetOut())
                {
                    this.m_out.Add(outData.Clone());
                }
            }
            catch { return(false); }
            return(true);
        }
コード例 #2
0
        public override bool Do()
        {
            try
            {
                var ExchangeMode = (FilterLogicMode)EnumPropertys["Exchange"].Value;

                BaseFilter drawSourceFilter = Graph.GetFilter(EnumPropertys["DrawSource"].Value);
                if (drawSourceFilter == null)
                {
                    return(false);
                }
                List <DataSrc> drawDatas = drawSourceFilter.GetOut();

                foreach (var src in Sources)
                {
                    IContourFilter searchFilter = src as IContourFilter;

                    if (searchFilter == null)
                    {
                        continue;
                    }

                    m_contours = searchFilter.GetResultContours();

                    int dataID  = 0;
                    var outData = src.GetOut();

                    // список коллекций кунтуров сопоставим с imgs
                    while ((dataID < outData.Count) && (dataID < m_contours.Count) && (dataID < drawDatas.Count))
                    {
                        string     dataInfo = "";
                        List <Mat> mergeLst = null;
                        switch (ExchangeMode)
                        {
                        case FilterLogicMode.Off:
                            mergeLst = m_contours[dataID].MergeWithContourMask(outData[dataID].Image, drawDatas[dataID].Image);
                            dataInfo = outData[dataID].Info;      //drawDatas[dataID].Info;
                            break;

                        case FilterLogicMode.On:
                            mergeLst = m_contours[dataID].MergeWithContourMask(drawDatas[dataID].Image, outData[dataID].Image);
                            dataInfo = outData[dataID].Info;
                            break;
                        }

                        foreach (var mergeImg in mergeLst)
                        {
                            this.m_out.Add(new DataSrc(mergeImg, dataInfo, false));
                        }

                        dataID++;
                    }
                }
            }
            catch (CvException ex)
            {
                return(false);
            }
            return(true);
        }
コード例 #3
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);
        }
コード例 #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;

                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);
        }
コード例 #5
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);
        }
コード例 #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);
        }
コード例 #7
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);
        }
コード例 #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;

                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);
        }