private IEnumerable <Perpetrator> GetPerpetrators(string json) { var perpetratorsJson = json != null?JsonConvert.DeserializeObject <JToken>(json) : new JArray(); var perpetrators = new List <Perpetrator>(); foreach (var perpetratorJson in perpetratorsJson) { var perpetrator = new Perpetrator { Name = perpetratorJson.Value <string>("Name"), Clothing = perpetratorJson.Value <string>("Clothing"), UniqueProperties = perpetratorJson.Value <string>("UniqueProperties") }; var skinColor = perpetratorJson["SkinColor"] != null?perpetratorJson.Value <string>("SkinColor") : null; perpetrator.SkinColor = skinColor != null ? (SkinColorEnum)Enum.Parse(typeof(SkinColorEnum), skinColor, true) : SkinColorEnum.Unknown; var sex = perpetratorJson["Sex"] != null?perpetratorJson.Value <string>("Sex") : null; perpetrator.Sex = sex != null ? (SexEnum)Enum.Parse(typeof(SexEnum), sex, true) : SexEnum.Unknown; var ages = perpetratorJson.Value <string>("AgeRange").Split('-'); perpetrator.MinimumAge = int.Parse(ages[0]); perpetrator.MaximumAge = int.Parse(ages[1]); perpetrators.Add(perpetrator); } return(perpetrators); }
public static bool Update(Perpetrator perp) { try { String update_sql = "UPDATE " + TABLE_NAME + " SET NAME=@name ,IS_A_STUDENT=@student,IS_ACTIVE=@active,GENDER=@gender WHERE ID=@id"; //Sql command sql_command = new MySqlCommand(); sql_command.Connection = (MySqlConnection)database.OpenConnection(); sql_command.CommandText = update_sql; sql_command.Parameters.AddWithValue("@id", perp.id); sql_command.Parameters.AddWithValue("@name", perp.name); sql_command.Parameters.AddWithValue("@student", "" + perp.is_a_student); sql_command.Parameters.AddWithValue("@active", "" + perp.is_still_active); sql_command.Parameters.AddWithValue("@gender", perp.gender); sql_command.Prepare(); //execute command database.Update(sql_command); Singleton.Update(perp); return(true); } catch (Exception) { return(false); } finally { CloseDatabaseConnection(); } }
private void DoneButton_Click(object sender, EventArgs e) { //reset mode of face detecting thread ReviewFaceDetectingThread.its_time_to_pick_perpetrator_faces = false; //create array for the identified perpetrator faces Image <Bgr, byte>[] perpetrator_faces = new Image <Bgr, byte> [image_list_view.SelectedItems.Count]; int i = 0; //save perpetrator images foreach (var item in image_list_view.SelectedItems) { //get the perpetrator face from the list of suspects faces suspect_faces.TryRemove(item.Index, out perpetrator_faces[i]); i++; } Perpetrator perpetrator = new Perpetrator(perpetrator_faces, true, ""); //clear datastore suspect_faces.Clear(); //open perpetrator details box PerpetratorDetailsForm form = new PerpetratorDetailsForm(perpetrator); //close this form this.Close(); form.ShowDialog(); }
public static bool Delete(int perpetrator_id) { try { //get the perp object associated with id Perpetrator perp = GetPerpetrator(perpetrator_id); if (perp != null) { //Delete cached object as well Singleton.Delete(perp); } String delete_sql = "DELETE FROM " + TABLE_NAME + " WHERE ID=@id"; //Sql command sql_command = new MySqlCommand(); sql_command.Connection = (MySqlConnection)database.OpenConnection(); sql_command.CommandText = delete_sql; sql_command.Parameters.AddWithValue("@id", perpetrator_id); sql_command.Prepare(); //execute command database.Update(sql_command); return(true); } catch (Exception) { return(false); } finally { CloseDatabaseConnection(); } }
public bool EnrollPerpetratorFaces(Perpetrator perpetrator) { try { foreach (var face in perpetrator.faces) { //CREATE NEW FACE OBJECT Face a_face = new Face(); a_face.face_position = new FacePosition(); a_face.facial_features = new FSDK.TPoint[2]; a_face.face_template = new byte[FSDK.TemplateSize]; a_face.image = new FSDK.CImage(face.ToBitmap()); a_face.is_perpetrator = true; a_face.id = perpetrator.id; EnrollFace(a_face); } return(true); } catch (Exception) { return(false); } }
public override int GetHashCode() { return(3 * Perpetrator.GetHashCode() + 5 * Countdown.GetHashCode() + 7 * Channel.GetHashCode() + 11 * Victim.GetHashCode()); }
//private bool another_crime; //NEW VICTIM CONSTRUCTOR public VictimsDetailsForm(Perpetrator perp, Crime crime) { //this.another_crime = false; this.perpetrator = perp; this.crime = crime; InitializeComponent(); ResetTextValues(); }
//THIS UPDATES A PERP FROM THE ACTIVE_PERPETRATORS ARRAY public static void Update(Perpetrator perp) { if (active_perpetrators.Contains(perp)) { int index = active_perpetrators.IndexOf(perp); active_perpetrators[index] = perp; } }
//CoNSTRUCTOR USED WHEN DISPLAYING DETAILS ABOUT A PERPETRATOR public PerpetratorDetailsForm(Perpetrator perpetrator, bool alert_mode) { InitializeComponent(); another_crime = true; this.perpetrator = perpetrator; SetPerpetratorDetails(); DisableControls(); }
public PerpetratorDetailWindow (Perpetrator perpetrator, EventHandler OnSave, Gtk.Window parent) : base(Gtk.WindowType.Toplevel) { this.Build (); this.OnSaved = OnSave; this.TransientFor = parent; this.Modal = true; show.Perpetrator = perpetrator; show.IsEditable = false; }
public PerpetratorDetailWindow (Victim victim, EventHandler OnSave, Gtk.Window parent) : base(Gtk.WindowType.Toplevel) { this.Build (); this.OnSaved = OnSave; this.TransientFor = parent; this.Modal = true; Perpetrator p = new Perpetrator (); p.Victim = victim; show.Perpetrator = p; show.IsEditable = true; }
//CONSTRUCTOR USED WHEN U WANT TO CAPTURE DETAILS ABOUT A PERP public PerpetratorDetailsForm(Perpetrator perpetrator) { InitializeComponent(); another_crime = true; this.perpetrator = perpetrator; comboBox_is_a_student.SelectedIndex = 0; comboBox_gender.SelectedIndex = 0; button_getCrimes.Visible = false; button_getCrimes.Enabled = false; button_is_apprehended.Visible = false; }
public static Perpetrator[] GetAllActivePerpetrators() { List <Perpetrator> perpetrators_list = new List <Perpetrator>(); try { //select sql String select_sql = "SELECT * FROM " + TABLE_NAME + " WHERE IS_ACTIVE='True'"; //Sql command sql_command = new MySqlCommand(); sql_command.Connection = (MySqlConnection)database.OpenConnection(); sql_command.CommandText = select_sql; sql_command.Prepare(); //get results in enum object data_reader = database.Select(sql_command); //loop thru em while (data_reader.Read()) { //create new student int id = data_reader.GetInt32(ID); String name = data_reader.GetString(NAME); Image <Bgr, byte>[] faces = GetPerpetratorFaces(id); bool is_a_student = data_reader.GetBoolean(IS_A_STUDENT); bool is_active = data_reader.GetBoolean(IS_ACTIVE); String gender = data_reader.GetString(GENDER); String created_at = data_reader.GetString(CREATED_AT); Perpetrator perp = new Perpetrator(id, name, faces, is_a_student, is_active, gender, created_at); //add student to list perpetrators_list.Add(perp); } } catch (Exception e) { Debug.WriteLine(e.Message); } finally { CloseDatabaseConnection(); } //return array of results return(perpetrators_list.ToArray()); ; }
public static bool Save(Perpetrator perp) { try { String insert_sql = "INSERT INTO " + TABLE_NAME + " (NAME,IS_A_STUDENT,IS_ACTIVE,GENDER)" + " values(@name,@is_a_student,@is_active,@gender) "; //sql command sql_command = new MySqlCommand(); sql_command.Connection = (MySqlConnection)database.OpenConnection(); sql_command.CommandText = insert_sql; sql_command.Parameters.AddWithValue("@name", perp.name); sql_command.Parameters.AddWithValue("@is_a_student", "" + perp.is_a_student); sql_command.Parameters.AddWithValue("@is_active", "" + perp.is_still_active); sql_command.Parameters.AddWithValue("@gender", perp.gender); sql_command.Prepare(); //execute query database.Insert(sql_command); //set perp id perp.id = (int)sql_command.LastInsertedId; //create file path String path = PATH_TO_IMAGES + perp.id + @"\"; //create folder for the perpetrator images FileManager.CreateFolderIfMissing(path); //save each face in that folder for (int i = 0; i < perp.faces.Length; i++) { //save using the perps name plus a unique number FileManager.SaveImage(path + perp.name + " " + i + ".png", perp.faces[i]); } return(true); } catch (Exception) { return(false); } finally { CloseDatabaseConnection(); } }
public bool CreatePerpetrator(PerpetratorCreate model) { var entity = new Perpetrator() { UserId = _userID, CrimeID = model.CrimeID, Crime = model.Crime, Name = model.Name, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Perpetrators.Add(entity); return(ctx.SaveChanges() == 1); } }
public void EnrollFacesTest() { Image<Gray, byte>[] images = { new Image<Gray, byte>(Image_Path + "1 0.png"), new Image<Gray, byte>(Image_Path + "1 1.png"), new Image<Gray, byte>(Image_Path + "1 2.png"), new Image<Gray, byte>(Image_Path + "1 3.png"), new Image<Gray, byte>(Image_Path + "1 4.png"), }; Perpetrator perp=new Perpetrator(); perp.faces=images; FacesManager manager = new FacesManager(); foreach (var image in images) { manager.EnrollFaces(perp); } //Assert.AreEqual(5, manager.known_faces_list.Count); }
private Panel CreateNewPerpPanel(Perpetrator perp) { ComboBox comboBox_gender = CreateGenderField(perp.gender); Label gender_label = CreateGenderLabel(); ComboBox comboBox_is_active = CreateIsActiveField(perp.is_still_active); Label is_active_label = CreateIsActiveLabel(); ComboBox comboBox_is_a_student = CreateIsAStudentField(perp.is_a_student); Label is_a_student_label = CreateIsAStudentLabel(); TextBox textBox_perpetrator_name = CreatePerpsNameField(perp.name); Label perps_name_label = CreatePerpsNameLabel(); PictureBox perpetrator_picture_box = CreatePerpsPictureBox(perp.faces[0].ToBitmap()); Label vertical_separator = CreateVerticalSeparator(); Control[] all_controls = { vertical_separator, comboBox_gender, gender_label, comboBox_is_active, is_active_label, comboBox_is_a_student, is_a_student_label, textBox_perpetrator_name, perps_name_label, perpetrator_picture_box }; Panel a_panel = new Panel(); a_panel.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; a_panel.Controls.AddRange(all_controls); a_panel.Font = new System.Drawing.Font("Calibri", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); a_panel.ForeColor = System.Drawing.SystemColors.ControlLight; a_panel.Location = new System.Drawing.Point(x, y); a_panel.Name = "panel2"; a_panel.Size = new System.Drawing.Size(515, 191); a_panel.TabIndex = 1; return(a_panel); }
public void EnrollFacesTest() { Image <Gray, byte>[] images = { new Image <Gray, byte>(Image_Path + "1 0.png"), new Image <Gray, byte>(Image_Path + "1 1.png"), new Image <Gray, byte>(Image_Path + "1 2.png"), new Image <Gray, byte>(Image_Path + "1 3.png"), new Image <Gray, byte>(Image_Path + "1 4.png"), }; Perpetrator perp = new Perpetrator(); perp.faces = images; FacesManager manager = new FacesManager(); foreach (var image in images) { manager.EnrollFaces(perp); } //Assert.AreEqual(5, manager.known_faces_list.Count); }
public CrimeDetailsForm(Perpetrator perpetrator_id) { this.perpetrator = perpetrator_id; InitializeComponent(); this.button_getVictims.Visible = false; }
//THIS DELETES A PERP FROM THE ACTIVE_PERPETRATORS ARRAY public static void Delete(Perpetrator perp) { active_perpetrators.Remove(perp); PerpetratorRecognitionThread.enroll_again = true; }
public void PerpetratorsManagerGetPerpetratorTest() { Perpetrator perp = PerpetratorsManager.GetPerpetrator(all_perps[0].id); Assert.IsNotNull(perp); }