public override bool Do() { try { BaseFilter SourceFilter = Graph.GetFilter(EnumPropertys["AppendSource"].Value); foreach (var scr in Sources) { foreach (var outData in scr.GetOut()) { this.m_out.Add(outData.Clone()); } } foreach (var outData in SourceFilter.GetOut()) { this.m_out.Add(outData.Clone()); } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
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); }
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); }
public override bool Do() { try { int comparableID = 0; BaseFilter betaSourceFilter = Graph.GetFilter(EnumPropertys["BetaSource"].Value); for (int SourcesId = 0; SourcesId < Sources.Count; SourcesId++) { var AlphaDatas = Sources[SourcesId].GetOut(); var betaDatas = betaSourceFilter.GetOut(); for (int ImgId = 0; ImgId < AlphaDatas.Count; ImgId++) { Mat alphaImg = AlphaDatas[ImgId].Image; Mat betaImg = null; if (FilePropertys["BetaFileImg"].FileName.Length > 0) { betaImg = CvInvoke.Imread(FilePropertys["BetaFileImg"].FileName); } else { if (comparableID < AlphaDatas.Count) { betaImg = betaDatas[comparableID].Image.Clone(); } else { betaImg = new Mat(alphaImg.Size, alphaImg.Depth, alphaImg.NumberOfChannels); } } comparableID++; Mat resImg = new Mat(); CvInvoke.AddWeighted(alphaImg, FloatPropertys["Alpha"].Value, betaImg, FloatPropertys["Beta"].Value, FloatPropertys["Gamma"].Value, resImg, DepthType.Cv8U); this.m_out.Add(new DataSrc(resImg, AlphaDatas[ImgId].Info, false)); } } } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } return(true); }
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); }
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); }