Bitmap drawHaarFeature(Bitmap Face, Elementator ID) { int cx, cy; double max_size_x = Face.Width / (p * 2); double max_size_y = Face.Height / (p * 2); double max_size = Math.Min(max_size_x, max_size_y); double sw, sh; int[,] active_rect; cx = (int)Math.Round(Face.Width / 2.0 + ID.px * Face.Width / ((p + 1) * 2)); cy = (int)Math.Round(Face.Height / 2.0 + ID.py * Face.Height / ((p + 1) * 2)); sw = max_size * (Math.Pow(Math.Sqrt(2) / 2, ID.sx)); sh = max_size * (Math.Pow(Math.Sqrt(2) / 2, ID.sy)); active_rect = genRectangle(cx, cy, sw, sh); Face = fillRect(Face, active_rect[0, 0], active_rect[0, 1], active_rect[1, 0], active_rect[1, 1], Color.Black); switch (ID.idMask) { case 1: Face = fillRect(Face, active_rect[0, 0], active_rect[0, 1], active_rect[1, 0], (int)Math.Round(active_rect[1, 1] / 2.0), Color.White); break; case 2: Face = fillRect(Face, 1 + (int)Math.Round(active_rect[0, 1] / 2.0), active_rect[0, 1], active_rect[1, 0], active_rect[1, 1], Color.White); break; case 3: Face = fillRect(Face, active_rect[0, 0], active_rect[0, 1], active_rect[1, 0], (int)Math.Round(active_rect[1, 1] / 3.0), Color.White); Face = fillRect(Face, active_rect[0, 0], active_rect[0, 1], 2 * (int)Math.Round(active_rect[1, 1] / 3.0) + 1, active_rect[1, 1], Color.White); break; case 4: Face = fillRect(Face, active_rect[0, 0], (int)Math.Round(active_rect[0, 1] / 3.0), active_rect[1, 0], active_rect[1, 1], Color.White); Face = fillRect(Face, 2 * (int)Math.Round(active_rect[0, 1] / 3.0) + 1, active_rect[0, 1], active_rect[1, 0], active_rect[1, 1], Color.White); break; case 5: Face = fillRect(Face, active_rect[0, 0], (int)Math.Round(active_rect[0, 1] / 2.0), active_rect[1, 0], (int)Math.Round(active_rect[1, 1] / 2.0), Color.White); Face = fillRect(Face, (int)Math.Round(active_rect[0, 1] / 2.0) + 1, active_rect[0, 1], (int)Math.Round(active_rect[1, 1] / 2.0) + 1, active_rect[1, 1], Color.White); break; case 6: Face = fillRect(Face, (int)Math.Round(active_rect[0, 1] / 4.0) + 1, 3 * (int)Math.Round(active_rect[0, 1] / 4.0), (int)Math.Round(active_rect[1, 1] / 4.0) + 1, 3 * (int)Math.Round(active_rect[1, 1] / 4.0), Color.White); break; case 7: Face = fillRect(Face, active_rect[0, 0], (int)Math.Round(active_rect[0, 1] / 3.0), active_rect[1, 0], (int)Math.Round(active_rect[1, 1] / 2.0), Color.White); Face = fillRect(Face, 2 * (int)Math.Round(active_rect[0, 1] / 3.0) + 1, active_rect[1, 0], active_rect[1, 0], (int)Math.Round(active_rect[1, 1] / 2.0), Color.White); Face = fillRect(Face, (int)Math.Round(active_rect[0, 1] / 3.0) + 1, 2 * (int)Math.Round(active_rect[0, 1] / 3.0), (int)Math.Round(active_rect[1, 1] / 2.0) + 1, active_rect[1, 1], Color.White); break; case 8: Face = fillRect(Face, active_rect[0, 0], (int)Math.Round(active_rect[0, 1] / 2.0), active_rect[1, 0], (int)Math.Round(active_rect[1, 1] / 3.0), Color.White); Face = fillRect(Face, active_rect[0, 0], (int)Math.Round(active_rect[0, 1] / 2.0), 2 * (int)Math.Round(active_rect[1, 1] / 3.0) + 1, active_rect[1, 1], Color.White); Face = fillRect(Face, (int)Math.Round(active_rect[0, 1] / 2.0) + 1, active_rect[0, 1], (int)Math.Round(active_rect[1, 1] / 3.0) + 1, 2 * (int)Math.Round(active_rect[1, 1] / 3.0), Color.White); break; } return Face; }
///////////////////////////////////////////////////////////////////////////////////////////////////////// Bitmap drawHaarFeature(Bitmap Image,int xb, int yb, int xe, int ye, Elementator ID) { Bitmap Face = new Bitmap(xe - xb, ye - yb); for (int x = xb; x <= xe; x++) { for (int y = yb; x <= ye; y++) { Face.SetPixel(x - xb, y - yb, Image.GetPixel(x, y)); } } return drawHaarFeature(Face, ID); }