0

I'm a doing a project on face detection using EmguCV in C#.My goal is to detect faces from a webcam. Meanwhile I am getting some errors.

I included all EmguCV dependencies and OpenCV dependencies.

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;

namespace demo
{
    public partial class Form1 : Form
    {
        private VideoCapture cap;
        private CascadeClassifier haar;
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            // passing 0 gets zeroth webcam
            cap = new VideoCapture(0);
            // adjust path to find your xml
            haar = new CascadeClassifier("haarcascade_frontalface_alt2.xml");
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            using (Image<Bgr, byte> nextFrame = cap.QueryFrame().ToImage<Bgr, Byte>())
            {
                if (nextFrame != null)
                {
                    // there's only one channel (greyscale), hence the zero index
                    //var faces = nextFrame.DetectHaarCascade(haar)[0];
                    Image<Gray, byte> grayframe = nextFrame.Convert<Gray, byte>();
                    var faces =
                            grayframe.DetectHaarCascade(haar, 1.4, 4,HAAR_DETECTION_TYPE.DO_CANNY_PRUNING,new Size(nextFrame.Width / 8, nextFrame.Height / 8))[0];
                    foreach (var face in faces)
                    {
                        nextFrame.Draw(face.rect, new Bgr(0, double.MaxValue, 0), 3);
                    }
                    pictureBox1.Image = nextFrame.ToBitmap();
                }
            }
        }
    }
}

I tried replacing DetectHaarcascade with Detectmultiscale.

ErrorCS1061:'Image' does not contain a definition for 'DetectHaarCascade' and no accessible extension method 'DetectHaarCascade' accepting a first argument of type 'Image' could be found (are you missing a using directive or an assembly reference?)

ErrorCS0103:The name 'HAAR_DETECTION_TYPE' does not exist in the current context

ErrorCS1579:foreach statement cannot operate on variables of type '?' because '?' does not contain a public instance definition for 'GetEnumerator'

AbdelAziz AbdelLatef
  • 3,650
  • 6
  • 24
  • 52
sandeep s
  • 11
  • 3
  • Might want to check the version of Emgu.CV that you have. The documentations seems to indicate that for `DetectHaarCascade` you'd need at least 2.4.2.1777 http://www.emgu.com/wiki/files/2.4.2/document/html/11c784fc-7d30-a921-07ec-ecdb7d217bbe.htm – juharr Sep 22 '19 at 13:43
  • Actually i'm using latest version of Emgu – sandeep s Sep 22 '19 at 14:23

1 Answers1

0

Try adding these librarirs:

using Emgu.CV.UI;
using System.Drawing;
using System.Diagnostics;
AbdelAziz AbdelLatef
  • 3,650
  • 6
  • 24
  • 52