I am new to Emgucv and I am working on face movement direction detection I had come across many codes in Internet but they are very difficult to understand.
So can you please provide a easy and understandable code or links for learning this situation.
Thanks in advance
Based on this :
Bitmap bmp = new Bitmap(); // your bitmap contain a face
Mat mat = GetMatFromSDImage(bmp);
using (var nextFrame = mat.ToImage<Bgr, Byte>())
{
if (nextFrame != null)
{
Image<Gray, byte> grayframe = nextFrame.Convert<Gray, byte>();
Rectangle[] faces = mHaarCascade.DetectMultiScale(grayframe, 1.1, 10, Size.Empty);
if (faces.Count() > 0)
{
// some faces are detected
// you can check the X and Y of faces here
}
}
}
private Mat GetMatFromSDImage(Bitmap image)
{
int stride = 0;
System.Drawing.Rectangle rect = new System.Drawing.Rectangle(0, 0, image.Width, image.Height);
System.Drawing.Imaging.BitmapData bmpData = image.LockBits(rect, System.Drawing.Imaging.ImageLockMode.ReadWrite, image.PixelFormat);
System.Drawing.Imaging.PixelFormat pf = image.PixelFormat;
if (pf == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
{
stride = image.Width * 4;
}
else
{
stride = image.Width * 3;
}
Image<Bgra, byte> cvImage = new Image<Bgra, byte>(image.Width, image.Height, stride, (IntPtr)bmpData.Scan0);
image.UnlockBits(bmpData);
return cvImage.Mat;
}
so faces
contains the array of Rectangle
bounding faces. you can check the X
and Y
property of the rectangles to check if it moves and compares it with the initial position to detect it's direction.
Update based on comment
To detect head rotation a simple solution can be eye detection. you can use haarcascade_eye.xml
to detect ayes. then you can calculate the rotation form each eye's X
and Y
position.
Here you can find a simple example of eye detection
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.