C# Emgu, could not be found Capture and HaarCascade

Viewed 10506

What did I miss?

VS could not be found Capture and HaarCascade. I added all opencv .dll and "Copy always".

Copy always

And added References of Emgu.

References

My Emgu is emgucv-windesktop 3.2.0.2682-сuda. Visual Studio 2017

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;
    using Emgu.CV;
    using Emgu.Util;
    using Emgu.CV.Structure;
    using Emgu.CV.CvEnum;
    using System.Windows;

    namespace Emgu.FaceDetection
    {
        public partial class Form1 : Form
        {
            private Capture cap;
            private HaarCascade haar;
            public Form1()
            {
                InitializeComponent();
            }
        }
    }
1 Answers

You can't use HaarCascade when using EmguCV3.X, it has been deprecated and replaced with CascadeClassifier

See here for an explination, the summary being it has changed to something akin to this:

CascadeClassifier _cascadeClassifier = new CascadeClassifier(@"C:\OPENCV_3.0.0\opencv\build\etc\haarcascades\" + "haarcascade_frontalface_alt2.xml");

A more complete example, and tutorial, using 3.X can be found here, a snippet from that blog:

private CascadeClassifier _cascadeClassifier;
_cascadeClassifier = new CascadeClassifier(Application.StartupPath + "/haarcascade_frontalface_alt_tree.xml");
using (var imageFrame = _capture.QueryFrame().ToImage<Bgr, Byte>())
                {
                    if (imageFrame != null)
                    {
                        var grayframe = imageFrame.Convert<Gray, byte>();
                        var faces = _cascadeClassifier.DetectMultiScale(grayframe, 1.1, 10, Size.Empty); //the actual face detection happens here
                    

foreach (var face in faces)
                    {
                        imageFrame.Draw(face, new Bgr(Color.BurlyWood), 3); //the detected face(s) is highlighted here using a box that is drawn around it/them
                       
                    }
                }
                imgCamUser.Image = imageFrame;                    
            }
Related