Esempio n. 1
0
        public MainWindow()
        {
            InitializeComponent();
            parametrs = new SIFTParametrs()
            {
                nFeatures         = 0,
                nOctaveLayers     = 5,
                contrastThreshold = 0.04,
                edgeThreshold     = 10,
                sigma             = 1.6
            };

            /*
             * Bitmap awad = new Bitmap("gps-disconnected.png");
             * for (int i = 0; i < awad.Width; i++)
             *  for (int j = 0; j < awad.Height; j++)
             *  {
             *      var col = awad.GetPixel(i, j);
             *      if (col.A > 200 ||( col.R == 0 && col.G == 0 && col.B == 0))
             *          awad.SetPixel(i, j, Color.FromArgb(0, 0, 255));
             *      else
             *          awad.SetPixel(i, j, Color.FromArgb(0, 0, 0, 0));
             *
             *
             *  }
             * awad.Save("lost-signalIcon.png", SD.Imaging.ImageFormat.Png);
             */
        }
Esempio n. 2
0
 public OriantatioOnMap(Image <Rgb, byte> Map, SIFTParametrs parametrs, double Compression = 4, double Radius = 20)
 {
     this.Map = Map;
     using (SIFT siftCPU = new SIFT(parametrs.nFeatures, parametrs.nOctaveLayers,
                                    parametrs.contrastThreshold, parametrs.edgeThreshold, parametrs.sigma))
     {
         VectorMapKeyPoint = new VectorOfKeyPoint(siftCPU.Detect(Map));
         VectorMapKeyPoint = FilterKeyPoint(VectorMapKeyPoint, Map, Compression, Radius, parametrs);
         siftCPU.Compute(Map, VectorMapKeyPoint, MapDiscriptors);
     }
 }
Esempio n. 3
0
        public Image <Rgb, byte> ShowMatches(Image <Rgb, byte> SubMap, int k, double uniquenessThreshold,
                                             int gridx, int gridy, double persent, SIFTParametrs parametrs, out System.Windows.Point?location)
        {
            location = null;
            VectorOfKeyPoint VectorSubMapKeyPoint = null;
            Mat SubMapDiscriptors          = null;
            VectorOfVectorOfDMatch matches = null;
            Mat mask = null;

            System.Drawing.Rectangle zone = new System.Drawing.Rectangle();
            Mat result     = new Mat();
            Mat homography = null;

            try
            {
                FindMatches(SubMap, out VectorSubMapKeyPoint, out SubMapDiscriptors, out matches, out mask, out zone, out homography,
                            k, uniquenessThreshold, parametrs);
                Features2DToolbox.DrawMatches(SubMap, VectorSubMapKeyPoint, Map, VectorMapKeyPoint, matches,
                                              result, new MCvScalar(0, 255, 0), new MCvScalar(0, 0, 255), mask, Features2DToolbox.KeypointDrawType.DrawRichKeypoints);
                PointF[] points = GetMapPoint(matches, mask);
                Point    point  = FoundCenter(points);
                if (MatchCorrect(Map.Mat, points, gridx, gridy, persent) && (!double.IsNaN(point.X) && !double.IsNaN(point.Y)))
                {
                    try
                    {
                        CvInvoke.Circle(result, point, 13, new MCvScalar(255, 0, 0), 10);
                        location = ImageTransform.SDtoSW(point);
                    }
                    catch { }
                }
                return(new Image <Rgb, byte>(result.Bitmap));
            }
            catch
            {
                return(Map);
            }
        }
Esempio n. 4
0
        public void FindMatches(Image <Rgb, byte> SubMap, out VectorOfKeyPoint VectorSubMapKeyPoint,
                                out Mat SubMapDiscriptors, out VectorOfVectorOfDMatch matches,
                                out Mat mask, out System.Drawing.Rectangle zone, out Mat homography, int k, double uniquenessThreshold, SIFTParametrs parametrs)
        {
            VectorSubMapKeyPoint = new VectorOfKeyPoint();
            SubMapDiscriptors    = new Mat();
            matches = new VectorOfVectorOfDMatch();
            zone    = new System.Drawing.Rectangle();
            using (SIFT siftCPU = new SIFT(parametrs.nFeatures, parametrs.nOctaveLayers,
                                           parametrs.contrastThreshold, parametrs.edgeThreshold, parametrs.sigma))
            {
                siftCPU.DetectAndCompute(SubMap, null, VectorSubMapKeyPoint, SubMapDiscriptors, false);
            }
            matches = new VectorOfVectorOfDMatch();
            using (Emgu.CV.Flann.LinearIndexParams ip = new Emgu.CV.Flann.LinearIndexParams())
                using (Emgu.CV.Flann.SearchParams sp = new SearchParams())
                    using (Emgu.CV.Features2D.DescriptorMatcher matcher = new FlannBasedMatcher(ip, sp))
                    {
                        matcher.Add(SubMapDiscriptors);
                        matcher.KnnMatch(MapDiscriptors, matches, k, null);
                    }

            mask = new Mat(matches.Size, 1, DepthType.Cv8U, 1);
            mask.SetTo(new MCvScalar(255));
            Features2DToolbox.VoteForUniqueness(matches, uniquenessThreshold, mask);

            homography = null;

            int nonZeroCount = CvInvoke.CountNonZero(mask);

            if (nonZeroCount >= 4)
            {
                nonZeroCount = Features2DToolbox.VoteForSizeAndOrientation(VectorSubMapKeyPoint, VectorMapKeyPoint,
                                                                           matches, mask, 1.5, 20);
                if (nonZeroCount >= 4)
                {
                    homography = Features2DToolbox.GetHomographyMatrixFromMatchedFeatures(
                        VectorSubMapKeyPoint, VectorMapKeyPoint, matches, mask, 2);
                }
            }
        }
Esempio n. 5
0
        private VectorOfKeyPoint FilterKeyPoint(VectorOfKeyPoint InputVecor, Image <Rgb, byte> SourceImage, double Compression, double Diameter, SIFTParametrs parametrs)
        {
            VectorOfKeyPoint OutputVector = null;

            SourceImage = SourceImage.Resize(1.0 / Compression, Emgu.CV.CvEnum.Inter.Area);
            using (SIFT siftCPU = new SIFT(parametrs.nFeatures, parametrs.nOctaveLayers,
                                           parametrs.contrastThreshold, parametrs.edgeThreshold, parametrs.sigma))
            {
                VectorOfKeyPoint MainVecor = new VectorOfKeyPoint(siftCPU.Detect(SourceImage, null));
                OutputVector = new VectorOfKeyPoint(RemoveFakeKeyPoint(MainVecor, InputVecor, Compression, Diameter));
            }
            return(OutputVector);
        }