internal extern static void CvPlanarObjectDetectorTrain( IntPtr objectDetector, IntPtr image, int npoints, int patchSize, int nstructs, int structSize, int nviews, ref LDetector keyPointDetector, ref PatchGenerator patchGenerator);
/// <summary> /// Train the planar object detector using the specific image /// </summary> /// <param name="image">The training image</param> /// <param name="npoints">Use 300 for default</param> /// <param name="patchSize">Use 31 for default</param> /// <param name="nstructs">Use 50 for default</param> /// <param name="structSize">Use 9 for default</param> /// <param name="nviews">Use 5000 for default</param> /// <param name="keyPointDetector">The keypoint detector to be used</param> /// <param name="patchGenerator">The patch generator to be used</param> public void Train(Image<Gray, byte> image, int npoints, int patchSize, int nstructs, int structSize, int nviews, ref LDetector keyPointDetector, ref PatchGenerator patchGenerator) { CvPlanarObjectDetectorTrain(Ptr, image, npoints, patchSize, nstructs, structSize, nviews, ref keyPointDetector, ref patchGenerator); }
/// <summary> /// Train the planar object detector using the specific image /// </summary> /// <param name="image">The training image</param> /// <param name="npoints">Use 300 for default</param> /// <param name="patchSize">Use 31 for default</param> /// <param name="nstructs">Use 50 for default</param> /// <param name="structSize">Use 9 for default</param> /// <param name="nviews">Use 5000 for default</param> /// <param name="keyPointDetector">The keypoint detector to be used</param> /// <param name="patchGenerator">The patch generator to be used</param> public void Train(Image <Gray, byte> image, int npoints, int patchSize, int nstructs, int structSize, int nviews, ref LDetector keyPointDetector, ref PatchGenerator patchGenerator) { CvPlanarObjectDetectorTrain(Ptr, image, npoints, patchSize, nstructs, structSize, nviews, ref keyPointDetector, ref patchGenerator); }
private static extern void CvPatchGeneratorInit(ref PatchGenerator pg);
private static extern void CvPlanarObjectDetectorTrain( IntPtr objectDetector, IntPtr image, int npoints, int patchSize, int nstructs, int structSize, int nviews, ref LDetector keyPointDetector, ref PatchGenerator patchGenerator);
private extern static void CvPatchGeneratorInit(ref PatchGenerator pg);
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); } }