Click here to Skip to main content
15,881,455 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more: , +
Hi I am doing some basic face and eyes detection using haar clasifiers how ever i am stuck as the final image does not have rectangles drawn on it. When i debug my code it does not go into foreach statement.I am not really sure where i am missing the trick.

C#
grayImage = orignalImage.Convert<Gray, byte>();
           hFAces = new HaarCascade("haarcascade_frontalface_default.xml");
           hEyes = new HaarCascade("haarcascade_eye.xml");
           MCvAvgComp[][] Storefaces = grayImage.DetectHaarCascade(hFAces, 1.2, 2, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(orignalImage.Width,orignalImage.Height));
           MCvAvgComp[][] StoreEyes = grayImage.DetectHaarCascade(hEyes, 1.2, 2, HAAR_DETECTION_TYPE.DO_CANNY_PRUNING, new Size(orignalImage.Width, orignalImage.Height));

           foreach(MCvAvgComp hFAce in Storefaces[0])
           {
               orignalImage.Draw(hFAce.rect, new Bgr(Color.Red), 2);
           }
           foreach (MCvAvgComp hEye in  StoreEyes[0])
           {
               orignalImage.Draw(hEye.rect, new Bgr(Color.Blue), 2);
           }

           pictureBox2.Image = orignalImage.ToBitmap();
Posted
Updated 29-Jan-14 3:40am
v2

1 solution

If you put a breakpoint on the initial foreach, are there any values in Storefaces or StoreEyes at all? Note that when I use DetectHaarCascade, I normally just pass in the HaarCascade - I don't use the other parameters. Have you tried just using:
C#
var StoreFaces = grayImage.DetectHaarCascade(hFAces);
var StoreEyes = grayImage.DetectHaarCascade(hEyes);
 
Share this answer
 
Comments
loraloper_22 29-Jan-14 10:01am    
HiWell it is amazing that it works when you just pass Cascades, but being student of the game i would like to know why is this because i have been following a tutorial
http://www.youtube.com/watch?v=E7LrsoyqATE
Looks like it worked well even if you pass more than one argument.?.
P.S It works fine when you only pass haarcascade but there has been precedence of people solving it
http://stackoverflow.com/questions/14294627/eye-and-mouth-detection-from-face-using-haar-cascades
http://stackoverflow.com/questions/3948926/opencv-emgu-c-sharp-face-extraction?rq=1
Thanks anyways
Pete O'Hanlon 29-Jan-14 10:12am    
My guess is that the Size is your problem. This parameter is the minimum scale of the face to search for - most people who use the none default size tend to use a fractional value of their overall image size, so you could set it to something like: new Size(orignalImage.Width / 2, orignalImage.Height / 2)
loraloper_22 29-Jan-14 10:22am    
HiAbsolutely right it was all about size
Pete O'Hanlon 29-Jan-14 10:23am    
I'm glad that's sorted. Good job and thanks for letting me know.
loraloper_22 29-Jan-14 10:25am    
Thanks a lot for your help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900