예제 #1
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);
        }
예제 #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;

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