//load images public void imreadall() { string Location = "C:\\major\\"; for (int i = 1; i <= trainData; i++) { int j = 0; Bitmap alphaBmp = (Bitmap)Image.FromFile(String.Concat(Location, Convert.ToString(i), ".jpg")); Bitmap bmp = ImageProcessingUtilities.emguCVconvert2Grayscale(alphaBmp); ImageProcessingUtilities.hist_equalize(bmp); BitmapData bmData = bmp.LockBits(new Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.ReadWrite, bmp.PixelFormat); unsafe { byte *p = (byte *)(void *)bmData.Scan0.ToPointer(); int stopAddress = (int)p + bmData.Stride * bmData.Height; while ((int)p != stopAddress) { // if (i==3) continue; C[j, i - 1] = p[0]; //images.SetValue(p[0], j, i - 1); j++; p++; } p = null; j = 0; } bmp.UnlockBits(bmData); } }
public static Bitmap getCroppedFace(Bitmap rawFrame, Rectangle faceRect) { int newFHeight = ((faceRect.Width) / 3) * 4; int gap = newFHeight - faceRect.Height; int top = 0; if ((faceRect.Top - (gap / 2)) > 0) { top = faceRect.Top - (gap / 2); } if ((faceRect.Top - (gap / 2) + newFHeight) > 480) { top = faceRect.Top - gap; } Rectangle face4isto3 = new Rectangle(faceRect.Left, top, faceRect.Width, newFHeight); Bitmap cFace = null; try { if (rawFrame != null) { Bitmap face_rgb = ImageProcessingUtilities.Resize((ImageProcessingUtilities.Crop(rawFrame, face4isto3)), 76, 101); //note: calling other grayscale convertion function causes recognition algorithm to stop working // So we call emguCV inbuild grayscale convertion function in ImageProcessingUtilities class //cFace =ImageProcessingUtilities.norm_rgb(ImageProcessingUtilities.emguCVconvert2Grayscale(face_rgb)); //cFace = face_rgb; cFace = ImageProcessingUtilities.emguCVconvert2Grayscale(face_rgb); } } catch (Exception ex) { //MessageBox.Show(ex.Message); } return(cFace); }