Exemplo n.º 1
0
 public FastBitmap GetImageWithDisplacement(FastBitmap currFrame, FastBitmap nextFrame, List<Point> edgePoints)
 {
     _nBytesPerPixel = currFrame.CCount;
     currFrame.LockBits();
     nextFrame.LockBits();
     byte[] currRgbValues = currFrame.Pixels;
     byte[] nextRgbValues = nextFrame.Pixels;
     Dictionary<Point, Point> displacements = new Dictionary<Point, Point>();
     foreach (Point edgePoint in edgePoints)
     {
         int edgePointPos;
         List<Color> pointVicinity = GetPointVicinity(edgePoint, currRgbValues, currFrame.Width, currFrame.Height, currFrame.Stride, out edgePointPos);
         _brief = new BRIEF((POINT_WINDOW_SIDE + 1) * (POINT_WINDOW_SIDE + 1),edgePointPos);
         string vicinityDescriptor = _brief.GetImageDescriptor(pointVicinity);
         if (pointVicinity[edgePointPos] != Color.Black)
         {
             Point nextFramePoint = FindPointDiscplacement(edgePoint, nextRgbValues, nextFrame.Width, nextFrame.Height, vicinityDescriptor, nextFrame.Stride, pointVicinity[edgePointPos]);
             displacements.Add(edgePoint, nextFramePoint);
         }
         else
             displacements.Add(edgePoint,edgePoint);
     }
     currFrame.UnlockBits();
     nextFrame.UnlockBits();
     DrawDisplacement(currFrame, displacements);
     return currFrame;
 }
Exemplo n.º 2
0
        public void Initialize(FastBitmap img)
        {
            _r = new Random();
            img.LockBits();
            _height = img.Height;
            _width = img.Width;

            int capacity = _width * _height;

            _pixels = new Pixel[capacity];

            int n = 0;
            for (int j = 0; j < _height; j++)
            {
                for (int i = 0 ; i < _width; i++)
                {
                    List<byte> samples = new List<byte>();
                    samples.Add(img[i,j]);
                    byte[] randomPixels = GetRandomGreyPixels(img, i, j);
                    samples.AddRange(randomPixels);
                    _pixels[n] = new Pixel(samples.ToArray());
                    n++;
                }
            }
            img.UnlockBits();
        }
Exemplo n.º 3
0
        public ReturnImage GetImageWithDisplacement(FastBitmap currFrame, FastBitmap nextFrame, List<Point> edgePoints)
        {
            _nBytesPerPixel = currFrame.CCount;
            currFrame.LockBits();
            nextFrame.LockBits();
            byte[] currRgbValues = currFrame.Pixels;
            byte[] nextRgbValues = nextFrame.Pixels;
            ConcurrentDictionary<Point, Point> displacements = new ConcurrentDictionary<Point, Point>();

            Parallel.ForEach(edgePoints, (edgePoint) =>
            {
                int edgePointPos;
                List<Color> pointVicinity = GetPointVicinity(edgePoint, currRgbValues, currFrame.Width, currFrame.Height, currFrame.Stride, out edgePointPos);
                _brief = new BRIEF((POINT_WINDOW_SIDE + 1) * (POINT_WINDOW_SIDE + 1), edgePointPos);
                string vicinityDescriptor = _brief.GetImageDescriptor(pointVicinity);
                if (pointVicinity[edgePointPos] != Color.Black)
                {
                    Point nextFramePoint = FindPointDiscplacement(edgePoint, nextRgbValues, nextFrame.Width, nextFrame.Height, vicinityDescriptor, nextFrame.Stride, pointVicinity[edgePointPos]);
                    displacements.TryAdd(edgePoint, nextFramePoint);
                }
                else
                    displacements.TryAdd(edgePoint, edgePoint);
            });

            currFrame.UnlockBits();
            nextFrame.UnlockBits();

            Frame frame = GetFrameByChanell(currFrame, displacements);
            //frames.Add();
            ReturnImage image = new ReturnImage(frame, currFrame);
            return image;
        }
 public Bitmap SubtracteBackground(FastBitmap source, double range, FastBitmap background)
 {
     source.LockBits();
     var arr = Subtraction(source, range, background);
     source.UnlockBits();
     arr = Closing(arr);
     return ConvertIntsToBitmap(arr, source);
 }
Exemplo n.º 5
0
 private FastBitmap ApplyMask(byte[] mask, FastBitmap img)
 {
     Bitmap result = new Bitmap(img.Width, img.Height);
     FastBitmap fb = new FastBitmap(result);
     fb.LockBits();
     img.LockBits();
     int n = 0;
     for (int j = 0; j < img.Height; j++)
     {
         for (int i = 0; i < img.Width; i++)
         {
             if (mask[n] > VibeModel.BackgroundByte)
             {
                 fb.SetPixel(i, j, img.GetPixel(i, j));
             }
             n++;
         }
     }
     img.UnlockBits();
     fb.UnlockBits();
     return fb;
 }