Ejemplo n.º 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);
        }