示例#1
0
        public void TestPlanarObjectDetector()
        {
            Image<Gray, byte> box = new Image<Gray, byte>("box.png");
             Image<Gray, byte> scene = new Image<Gray,byte>("box_in_scene.png");
             //Image<Gray, Byte> scene = box.Rotate(1, new Gray(), false);

             using (PlanarObjectDetector detector = new PlanarObjectDetector())
             {
            Stopwatch watch = Stopwatch.StartNew();
            LDetector keypointDetector = new LDetector();
            keypointDetector.SetDefaultParameters();

            PatchGenerator pGen = new PatchGenerator();
            pGen.SetDefaultParameters();

            detector.Train(box, 300, 31, 50, 9, 5000, ref keypointDetector, ref pGen);
            watch.Stop();
            Trace.WriteLine(String.Format("Training time: {0} milliseconds.", watch.ElapsedMilliseconds));

            MKeyPoint[] modelPoints = detector.GetModelPoints();
            int i = modelPoints.Length;

            HomographyMatrix h = new HomographyMatrix();
            watch = Stopwatch.StartNew();
            PointF[] corners = detector.Detect(scene, h);
            watch.Stop();
            Trace.WriteLine(String.Format("Detection time: {0} milliseconds.", watch.ElapsedMilliseconds));

            foreach (PointF c in corners)
            {
               scene.Draw(new CircleF(c, 2), new Gray(255), 1);
            }
            scene.DrawPolyline(Array.ConvertAll<PointF, Point>(corners, Point.Round), true, new Gray(255), 2);
             }
        }
示例#2
0
        public void TestLDetectorAndSelfSimDescriptor()
        {
            Image<Gray, byte> box = new Image<Gray, byte>("box.png");
             LDetector detector = new LDetector();
             detector.SetDefaultParameters();

             MKeyPoint[] keypoints = detector.DetectKeyPoints(box, 200, true);

             Point[] pts = Array.ConvertAll<MKeyPoint, Point>(keypoints, delegate(MKeyPoint k) { return Point.Round(k.Point); });

             SelfSimDescriptor descriptor = new SelfSimDescriptor(5, 41, 3, 7, 20);
             int descriptorSize = descriptor.DescriptorSize;

             float[] descriptors = descriptor.Compute(box, new Size(20, 20), pts);

             float absSum = 0;
             foreach (float f in descriptors)
            absSum += Math.Abs(f);

             //TODO: Find out why selfsimilarity always return descriptors of all zeros. Probaboly a bug in the opencv C++ code
             //Assert.AreNotEqual(0, absSum, "The sum of the descriptor should not be zero");

             Assert.AreEqual(descriptors.Length / descriptor.DescriptorSize, pts.Length);

             foreach (MKeyPoint kp in keypoints)
             {
            box.Draw(new CircleF(kp.Point, kp.Size), new Gray(255), 1);
             }
        }