Пример #1
0
        public void Run()
        {
            var dst = new Mat(FilePath.Lenna, LoadMode.Color);
            var gray = new Mat(FilePath.Lenna, LoadMode.GrayScale);

            StarDetector detector = new StarDetector(45);
            KeyPoint[] keypoints = detector.Run(gray);

            if (keypoints != null)
            {
                var color = new Scalar(0, 255, 0);
                foreach (KeyPoint kpt in keypoints)
                {
                    float r = kpt.Size / 2;
                    Cv2.Circle(dst, kpt.Pt, (int)r, color, 1, LineType.Link8, 0);
                    Cv2.Line(dst, 
                        new Point2f(kpt.Pt.X + r, kpt.Pt.Y + r), 
                        new Point2f(kpt.Pt.X - r, kpt.Pt.Y - r), 
                        color, 1, LineType.Link8, 0);
                    Cv2.Line(dst, 
                        new Point2f(kpt.Pt.X - r, kpt.Pt.Y + r), 
                        new Point2f(kpt.Pt.X + r, kpt.Pt.Y - r), 
                        color, 1, LineType.Link8, 0);
                }
            }

            using (new Window("StarDetector features", dst))
            {
                Cv.WaitKey();
            }
        }
Пример #2
0
        /// <summary>
        /// Extracts keypoints by C++-style code (cv::StarDetector)
        /// </summary>
        /// <param name="img"></param>
        /// <param name="cimg"></param>
        private void CppStyleStarDetector(IplImage img, IplImage cimg)
        {
            Mat src = new Mat(img, false);
            Mat dst = new Mat(cimg, false);
            StarDetector detector = new StarDetector(45);
            KeyPoint[] keypoints = detector.Run(src);

            if (keypoints != null)
            {
                foreach (KeyPoint kpt in keypoints)
                {
                    float r = kpt.Size / 2;
                    Cv2.Circle(dst, kpt.Pt, (int)r, new CvColor(0, 255, 0), 1, LineType.Link8, 0);
                    Cv2.Line(dst, new Point2f(kpt.Pt.X + r, kpt.Pt.Y + r), new Point2f(kpt.Pt.X - r, kpt.Pt.Y - r), new CvColor(0, 255, 0), 1, LineType.Link8, 0);
                    Cv2.Line(dst, new Point2f(kpt.Pt.X - r, kpt.Pt.Y + r), new Point2f(kpt.Pt.X + r, kpt.Pt.Y - r), new CvColor(0, 255, 0), 1, LineType.Link8, 0);
                }
            }

        }