private void button4_Click(object sender, EventArgs e) { DialogResult dialogResult = MessageBox.Show("Delete user.All profile and picture will dissapear.", "Caution", MessageBoxButtons.YesNo); if (dialogResult == DialogResult.Yes) { db.DeleteUser(Int32.Parse(userId)); db.DeleteAllUserImage(Int32.Parse(userId)); FillData(); imageBox7.Image = null; } else if (dialogResult == DialogResult.No) { //do something else } }
private void button1_Click(object sender, EventArgs e) { string dateTemp = dateTimePicker1.Value.ToString("s"); if (mydb.checkUserProfile(textBox1.Text, textBox2.Text)) { mydb.InsertUserData(textBox1.Text, textBox2.Text, dateTemp, comboBox1.Text, comboBox2.Text); } newid = mydb.getUserId(textBox1.Text, textBox2.Text, dateTemp, comboBox1.Text); if (newid != 0) { if (!TrainFrame(newid)) { mydb.DeleteUser(newid); } else { MessageBox.Show("trainsuccess"); } } }
private void TrainFrame(object sender, EventArgs e) { try { imageFrameT = captureT.QueryFrame(); Image <Gray, byte> darkimage = new Image <Gray, byte>(ROIwidth, ROIheight); Image <Gray, byte> cropimage = new Image <Gray, byte>(ROIwidth, ROIheight); Image <Gray, byte> plainimage = new Image <Gray, byte>(ROIwidth, ROIheight); //ArrayList pic = new ArrayList(); if (imageFrameT != null) { Image <Gray, byte> greyImage = imageFrameT.Copy().Convert <Gray, byte>(); var faces = face.Detect(greyImage, 1.3, 6, HAAR_DETECTION_TYPE.FIND_BIGGEST_OBJECT, new Size(120, 120), new Size(300, 300)); if (faces.Length > 0) { label6.ForeColor = Color.Chocolate; label6.Text = "Tracking Face"; foreach (var facecount in faces) { facePosition = new Point(facecount.rect.X, facecount.rect.Y); faceRectangleSize = new Size(facecount.rect.Width, facecount.rect.Height); faceRectangle = new Rectangle(facePosition, faceRectangleSize); greyImage.ROI = faceRectangle; var eyeObjects = eyeWithGlass.DetectMultiScale(greyImage, 1.3, 6, minEye, maxEye); greyImage.ROI = Rectangle.Empty; if (eyeObjects.Length == 2) { Console.WriteLine("eye"); if (eyeObjects[0].X > eyeObjects[1].X) { var temp = eyeObjects[0]; eyeObjects[0] = eyeObjects[1]; eyeObjects[1] = temp; } int betweeneLength = eyeObjects[1].X - eyeObjects[0].X; int lefteyebrowpoint = eyeObjects[0].X; // int righteyebrowpoint = eyeObjects[1].X + eyeObjects[1].Width; // int margin = (int)((1.5 / 8.0) * betweeneLength); int neareyebrowpoint = (int)(0.2 * betweeneLength); int faceheight = (int)(2.3 * betweeneLength); realFacePosition = new Point(facePosition.X + lefteyebrowpoint - margin, facePosition.Y + eyeObjects[0].Y - neareyebrowpoint); realfaceRectangleSize = new Size((righteyebrowpoint + margin) - (lefteyebrowpoint - margin), faceheight); realfaceRectangle = new Rectangle(realFacePosition, realfaceRectangleSize); greyImage.ROI = realfaceRectangle; imageFrameT.Draw(realfaceRectangle, new Bgr(Color.LimeGreen), 2); if (trainflag) { //get bigger face in frame cropimage = greyImage.Resize(ROIwidth, ROIheight, INTER.CV_INTER_LINEAR); if (!cropimage.Equals(darkimage)) { cropimage._EqualizeHist(); CvInvoke.cvFastNlMeansDenoising(cropimage, cropimage, 3, 7, 21); plainimage = cropimage.Copy(); Point[] pL = new Point[3]; Point[] pR = new Point[3]; int y0 = 105; int y1 = 174; int x0 = 0; int x1 = 34; int x2 = 105; int x3 = 139; pL[0] = new Point(x0, y0); pL[1] = new Point(x0, y1); pL[2] = new Point(x1, y1); pR[0] = new Point(x3, y0); pR[1] = new Point(x3, y1); pR[2] = new Point(x2, y1); cropimage.FillConvexPoly(pL, new Gray(128)); cropimage.FillConvexPoly(pR, new Gray(128)); //cropimage = cropimage.SmoothMedian(3); imageBox7.Image = cropimage; //line 2 cropimage.Save(folderPath + tempPath); string dbPath = (folderPath + tempPath).Replace("\\", "/"); plainimage.Save(folderPath + tempPath2); string dbPathPlain = (folderPath + tempPath2).Replace("\\", "/"); mydb.InsertImageTraining(newid, dbPathPlain, dbPath, true); label6.ForeColor = Color.ForestGreen; label6.Text = "Success"; //File.Delete(tempPath); //eigenRecog.reloadData(); imageBox7.Image = cropimage; imageCount++; } else { label6.ForeColor = Color.Red; label6.Text = "Fail"; } if (imageCount > 25) { trainflag = false; imageCount = 1; label6.ForeColor = Color.LimeGreen; label6.Text = "Finish"; } } } } } else { label6.ForeColor = Color.DeepSkyBlue; label6.Text = "Idle"; } imageBox1.Image = imageFrameT; } else { mydb.DeleteUser(newid); } } catch { // MessageBox.Show("Enable the face detection first", "Training Fail", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }