コード例 #1
0
        public override bool Do()
        {
            try
            {
                var bReqFullUpdate = !m_isSelfClearOut || (histogramsResults.Count == 0);
                if (bReqFullUpdate)
                {
                    histogramsResults.Clear();
                }

                IMovingPredict    movingPredict = null;
                MovingPredictType movingType    = (MovingPredictType)EnumPropertys["MovingType"].Value;
                switch (movingType)
                {
                case MovingPredictType.MovingAverage:
                    movingPredict = new MovingAverage(IntPropertys["MovingRange"].Value);
                    break;

                case MovingPredictType.MovingMediana:
                    movingPredict = new MovingMediana(IntPropertys["MovingRange"].Value);
                    break;

                default:
                    movingPredict = new MovingAverage(IntPropertys["MovingRange"].Value);
                    break;
                }

                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)
                        {
                            histogramsResults.Add(RGBHistogram.GetHistograms(outDatas[dataID].Image));
                        }

                        Mat copy = outDatas[dataID].Image.Clone();


                        RGBHistogram.DrawChannel(copy, IntPropertys["x_show"].Value, IntPropertys["y_show"].Value,
                                                 FloatPropertys["scaleX"].Value, FloatPropertys["scaleY"].Value, movingPredict,
                                                 histogramsResults[listID], 0, new Bgr(0, 0, 255).MCvScalar, new Bgr(50, 0, 255).MCvScalar, false);


                        RGBHistogram.DrawChannel(copy, IntPropertys["x_show"].Value, IntPropertys["y_show"].Value,
                                                 FloatPropertys["scaleX"].Value, FloatPropertys["scaleY"].Value, movingPredict,
                                                 histogramsResults[listID], 1, new Bgr(255, 0, 0).MCvScalar, new Bgr(255, 0, 50).MCvScalar, false);

                        RGBHistogram.DrawChannel(copy, IntPropertys["x_show"].Value, IntPropertys["y_show"].Value,
                                                 FloatPropertys["scaleX"].Value, FloatPropertys["scaleY"].Value, movingPredict,
                                                 histogramsResults[listID], 2, new Bgr(0, 255, 0).MCvScalar, new Bgr(50, 255, 50).MCvScalar, false);

                        listID++;
                        this.m_out.Add(new DataSrc(copy, outDatas[dataID].Info, false));
                    }
                }
            }
            catch (Exception ex) {
                return(false);
            }
            return(true);
        }
コード例 #2
0
        public static void DrawChannel(Mat img, int xPos, int yPos, double scaleX, double scaleY, IMovingPredict movingPredict, double[,] histograms, int nChannel, MCvScalar colorFill, MCvScalar color, bool isFill = false)
        {
            movingPredict.Clear();
            double preValue = 0;

            for (int nColor = 0; nColor < 255; nColor++)
            {
                double currentValue = histograms[nChannel, nColor];
                currentValue = movingPredict.Predict(currentValue); // пропускаю currentValue через скользящую функцию
                DrawBar(img, xPos, yPos, nColor, scaleX, scaleY, preValue, currentValue, colorFill, color, isFill);
                preValue = currentValue;
            }
        }