Ejemplo n.º 1
0
        private Frame GetFrameByChanell(FastBitmap source, ConcurrentDictionary<Point, Point> displacements)
        {
            Pen pen = new Pen(Color.Aqua);
            pen.EndCap = LineCap.ArrowAnchor;
            RemoveLongLine(displacements);

            Bitmap bmp = new Bitmap(source.Width, source.Height);
            using (Graphics graph = Graphics.FromImage(bmp))
            {
                graph.FillRectangle(Brushes.White, new Rectangle(0, 0, source.Width, source.Height));
            }
            double[,] chanelXP = new double[source.Width, source.Height];
            double[,] chanelXM = new double[source.Width, source.Height];
            double[,] chanelYP = new double[source.Width, source.Height];
            double[,] chanelYM = new double[source.Width, source.Height];

            Graphics graphics = Graphics.FromImage(source.Source);

            foreach (var displacement in displacements)
            {
                int differenceX = displacement.Value.X - displacement.Key.X,
                    differenceY = displacement.Value.Y - displacement.Key.Y;
                bool isPosX = true, isPosY = true;
                if (differenceX < 0)
                    isPosX = false;
                if (differenceY < 0)
                    isPosY = false;

                differenceX = (int)(255 * (1 - Math.Min(1, Math.Abs((double)differenceX / 10))));
                differenceY = (int)(255 * (1 - Math.Min(1, Math.Abs((double)differenceY / 10))));

                double brightnessXColor = Color.FromArgb(differenceX, differenceX, differenceX).GetBrightness();
                double brightnessYColor = Color.FromArgb(differenceY, differenceY, differenceY).GetBrightness();

                for (int y = displacement.Key.Y - 1; y <= displacement.Key.Y + 1; ++y)
                    for (int x = displacement.Key.X - 1; x <= displacement.Key.X + 1; ++x)
                    {
                        if (isPosX)
                        {
                            chanelXP[x, y] = brightnessXColor;
                        }
                        else
                        {
                            //differenceX = Math.Abs(differenceX);
                            chanelXM[x, y] = brightnessXColor;
                        }
                        if (isPosY)
                        {
                            chanelYM[x, y] = brightnessYColor;
                        }
                        else
                        {
                            //differenceY = Math.Abs(differenceY);
                            chanelYP[x, y] = brightnessYColor;
                        }
                    }
                if (displacement.Key.X == displacement.Value.X && displacement.Key.Y == displacement.Value.Y)
                    graphics.DrawLine(pen, displacement.Key, new Point(displacement.Value.X + 2, displacement.Value.Y + 2));
                else
                    graphics.DrawLine(pen, displacement.Key, displacement.Value);
            }
            GaussianBlur blur = new GaussianBlur();
            Frame frame = new Frame(blur.Filter(chanelXP), blur.Filter(chanelXM), blur.Filter(chanelYP), blur.Filter(chanelYM));

            return frame;
        }
Ejemplo n.º 2
0
 public ReturnImage(Frame frame, FastBitmap bitmap)
 {
     this.frame = frame;
     this.bitmap = bitmap;
 }
Ejemplo n.º 3
0
 private bool GetFlow(byte[] subMask, FastBitmap realFrame, FastBitmap subFrame, MemoryStream stream, string file, out Frame frame)
 {
     Frame localFrame =null;
     bool isNext = true;
     List<Point> corners = _harries.Corner(subMask, subFrame.Width, subFrame.Height);
     if (corners.Count > 0)
     {
         _nextFrame = GetBitmap(_currentPosition + (float)TimerInterval, stream, file);
         if (_nextFrame != null)
         {
             _nextSubMask = _vibeModel.GetMask(_nextFrame);
             _nextSubFrame = ApplyMask(_nextSubMask, _nextFrame);
             localFrame = _lucasKanade.GetImageWithDisplacement(subFrame, _nextSubFrame, corners).frame;
             _currentPosition += (float)TimerInterval;
         }
         else
             isNext = false;
     }
     frame = localFrame;
     return isNext;
 }