Exemplo n.º 1
0
        public static Result Run(AirPhoto mainMap, AirPhoto image)
        {
            SIFT      sift        = new SIFT();
            BFMatcher matcher     = new BFMatcher();
            Result    res         = new Result(mainMap, image);
            Mat       map         = new Mat(res.MainMap.FileName);
            Mat       singleImage = new Mat(res.SingleImage.FileName);

            sift.Run(map, null, out res.MainMap.keyPoints, res.MainMap.Descriptors);
            sift.Run(singleImage, null, out res.SingleImage.keyPoints, res.SingleImage.Descriptors);
            res.Matches = matcher.Match(res.MainMap.Descriptors, res.SingleImage.Descriptors);

            for (int i = 0; i < res.MainMap.Descriptors.Rows; i++)
            {
                double dist = res.Matches[i].Distance;
                if (dist < res.Min_dist)
                {
                    res.Min_dist = dist;
                }
                if (dist > res.Max_dist)
                {
                    res.Max_dist = dist;
                }
            }
            for (int i = 0; i < res.MainMap.Descriptors.Rows; i++)
            {
                if (res.Matches[i].Distance <= Math.Max(2 * res.Min_dist, 0.25))
                {
                    res.Good_matchesRAW.Add(res.Matches[i]);
                    res.Current_good_matches.Add(res.Matches[i]);
                }
            }
            for (int i = 0; i < res.Good_matchesRAW.Count; i++)
            {
                res.MainMap.Keypoints_goodRAW.Add(res.MainMap.Keypoints[res.Good_matchesRAW[i].QueryIdx].Pt);
                res.SingleImage.Keypoints_goodRAW.Add(res.SingleImage.Keypoints[res.Good_matchesRAW[i].TrainIdx].Pt);
                res.MainMap.Current_good_keypoints.Add(res.MainMap.Keypoints[res.Good_matchesRAW[i].QueryIdx].Pt);
                res.SingleImage.Current_good_keypoints.Add(res.SingleImage.Keypoints[res.Good_matchesRAW[i].TrainIdx].Pt);
            }
            Mat view             = new Mat();
            Mat map_draw         = new Mat(res.MainMap.FileName);
            Mat singleImage_draw = new Mat(res.SingleImage.FileName);

            Cv2.DrawMatches(map, res.MainMap.Keypoints, singleImage, res.SingleImage.Keypoints, res.Current_good_matches, view);
            for (int i = 0; i < res.MainMap.Current_good_keypoints.Count; i++)
            {
                Cv.DrawCircle((IplImage)map_draw,
                              new CvPoint(Convert.ToInt32(res.MainMap.Current_good_keypoints[i].X),
                                          Convert.ToInt32(res.MainMap.Current_good_keypoints[i].Y)),
                              map_draw.Width / 500,
                              CvColor.Red, 2);
            }
            for (int i = 0; i < res.SingleImage.Current_good_keypoints.Count; i++)
            {
                Cv.DrawCircle((IplImage)singleImage_draw,
                              new CvPoint(Convert.ToInt32(res.SingleImage.Current_good_keypoints[i].X),
                                          Convert.ToInt32(res.SingleImage.Current_good_keypoints[i].Y)),
                              singleImage_draw.Width / 100,
                              CvColor.Red, 2);
            }
            res.MainMap.RAWwithKP     = map_draw;
            res.SingleImage.RAWwithKP = singleImage_draw;
            res.RAWmatches            = view;
            return(res);
        }
Exemplo n.º 2
0
 public Result(AirPhoto mainMap, AirPhoto singleImage)
 {
     MainMap     = mainMap;
     SingleImage = singleImage;
 }