static void Run() { using (Mat image = CvInvoke.Imread("cat.jpg", LoadImageType.AnyColor | LoadImageType.AnyDepth)) using (LatentSvmDetector detector = new LatentSvmDetector(new string[] { "cat.xml" })) { Stopwatch watch = Stopwatch.StartNew(); MCvObjectDetection[] regions = detector.Detect(image, 0.5f); watch.Stop(); foreach (MCvObjectDetection region in regions) { CvInvoke.Rectangle(image, region.Rect, new MCvScalar(0, 0, 255)); } ImageViewer.Show(image, String.Format("Object detected in {0} milliseconds", watch.ElapsedMilliseconds)); } }
public void TestLatenSVM() { using (LatentSvmDetector detector = new LatentSvmDetector(new string[] { EmguAssert.GetFile("cat.xml") })) { String[] files = new String[] { "cat.png"}; for (int idx = 0; idx < files.Length; idx++) using (Mat img = EmguAssert.LoadMat(files[idx])) { MCvObjectDetection[] results = detector.Detect(img, 0.5f); if (results.Length >= 0) { double maxScore = results[0].Score; Rectangle result = results[0].Rect; for (int i = 1; i < results.Length; ++i) { if (results[i].Score > maxScore) { maxScore = results[i].Score; result = results[i].Rect; } } CvInvoke.Rectangle(img, result, new MCvScalar(0, 0, 255)); //Emgu.CV.UI.ImageViewer.Show(img); } } } }