void GiveUser(User current) { faceTrackingViewer.stopTracking(); this.isfaceTrackerOn = false; if (this.isUserNew) { if (current.name.Length > 0) { faceTrackingViewer.stopTracking(); this.isfaceTrackerOn = false; this.scanpanel.Visibility = System.Windows.Visibility.Collapsed; if (string.Compare(this.currentUser.name, current.name, true) == 0) { this.welcomeMassage.Text = "We have found your scan if thats incorecct click on rescan!"; this.welcomeMassage.Visibility = System.Windows.Visibility.Visible; this.rescan.Visibility = System.Windows.Visibility.Visible; } } else { // new user registering, start learner faceTrackingViewer.stopTracking(); this.isfaceTrackerOn = false; this.currentUser.faceParams = current.faceParams; this.currentUser.name = this.Username.Text; this.scanpanel.Visibility = System.Windows.Visibility.Collapsed; this.ImagePanel.Visibility = System.Windows.Visibility.Visible; } } else { if (current.name.Length > 0) { if (String.Compare(current.name, this.currentUser.name, true) == 0) { faceTrackingViewer.stopTracking(); this.isfaceTrackerOn = false; Console.WriteLine("The name is " + current.name); this.scanpanel.Visibility = System.Windows.Visibility.Collapsed; this.InitialPanel.Visibility = System.Windows.Visibility.Visible; this.New_Account.Visibility = System.Windows.Visibility.Collapsed; this.login.Visibility = System.Windows.Visibility.Collapsed; this.rescan.Visibility = System.Windows.Visibility.Collapsed; this.welcomeMassage.Visibility = System.Windows.Visibility.Visible; this.welcomeMassage.Text = "Hello " + current.name + "! " + "Start drawing your pattern when the circle is blue."; userImage = new BitmapImage(new Uri(current.imgPath)); myImageBox.Source = handSource; this.myImageBox.Visibility = Visibility.Visible; this.sensor.DepthFrameReady += this.SensorDepthFrameReady; this.sensor.SkeletonFrameReady += this.SensorSkeletonFrameReady; Queue<ThreeDAuth.Point2d> passwordQueue = new Queue<ThreeDAuth.Point2d>(current.password); gValidator = new ThreeDAuth.GestureValidator(passwordQueue, 20); gValidator.OnCompletedValidation += new CompletedValidation(gValidator_OnCompletedValidation); } else { faceTrackingViewer.stopTracking(); this.isfaceTrackerOn = false; Console.WriteLine("The name is " + current.name); this.scanpanel.Visibility = System.Windows.Visibility.Collapsed; this.InitialPanel.Visibility = System.Windows.Visibility.Visible; this.New_Account.Visibility = System.Windows.Visibility.Collapsed; this.login.Visibility = System.Windows.Visibility.Collapsed; this.rescan.Visibility = System.Windows.Visibility.Visible; this.byPass.Visibility = System.Windows.Visibility.Visible; this.welcomeMassage.Visibility = System.Windows.Visibility.Visible; this.welcomeMassage.Text = "Hello " + this.currentUser.name + "! " + "We did not find the right match. Please rescan"; } } else { faceTrackingViewer.stopTracking(); this.isfaceTrackerOn = false; Console.WriteLine("The name is " + current.name); this.scanpanel.Visibility = System.Windows.Visibility.Collapsed; this.InitialPanel.Visibility = System.Windows.Visibility.Visible; this.New_Account.Visibility = System.Windows.Visibility.Collapsed; this.login.Visibility = System.Windows.Visibility.Collapsed; this.rescan.Visibility = System.Windows.Visibility.Visible; this.byPass.Visibility = System.Windows.Visibility.Visible; this.welcomeMassage.Visibility = System.Windows.Visibility.Visible; this.welcomeMassage.Text = "Hello " + this.Username.Text + "! " + "We did not find you. Please rescan"; } } }
private void SaveUser(User user) { String filename = "users.xml"; System.Xml.XmlDocument userFile = new System.Xml.XmlDocument(); try { userFile.Load(filename); System.Xml.XmlNodeList users = userFile.GetElementsByTagName("user"); bool existingUser = false; System.Xml.XmlNode node = null; foreach (System.Xml.XmlNode userNode in users) { if (userNode["name"].InnerText.Equals(user.name)) { existingUser = true; node = userNode; } } if (!existingUser) { node = userFile.CreateNode(System.Xml.XmlNodeType.Element, "user", null); System.Xml.XmlNode nameNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "name", null); nameNode.InnerText = user.name; System.Xml.XmlNode imageNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "user-image", null); imageNode.InnerText = user.imgPath; System.Xml.XmlNode faceParamsNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "face-params", null); // Need to get all the face params in here FaceClassifier classifier = CurrentObjectBag.SCurrentFaceClassifier; // add by Anton - write face params to XML int tempIdCounter = 1; foreach (ThreeDAuth.Point2d point in user.faceParams) { System.Xml.XmlNode paramNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "param", null); System.Xml.XmlNode id = userFile.CreateNode(System.Xml.XmlNodeType.Element, "id", null); System.Xml.XmlNode mean = userFile.CreateNode(System.Xml.XmlNodeType.Element, "mean", null); System.Xml.XmlNode sdev = userFile.CreateNode(System.Xml.XmlNodeType.Element, "stdev", null); mean.InnerText = "" + point.x; sdev.InnerText = "" + point.y; id.InnerText = "" + tempIdCounter; tempIdCounter++; paramNode.AppendChild(id); paramNode.AppendChild(mean); paramNode.AppendChild(sdev); faceParamsNode.AppendChild(paramNode); } System.Xml.XmlNode passwordNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "points", null); foreach (ThreeDAuth.Point2d point in user.password) { System.Xml.XmlNode pointNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "point", null); System.Xml.XmlNode xCoord = userFile.CreateNode(System.Xml.XmlNodeType.Element, "x", null); System.Xml.XmlNode yCoord = userFile.CreateNode(System.Xml.XmlNodeType.Element, "y", null); xCoord.InnerText = "" + point.x; yCoord.InnerText = "" + point.y; pointNode.AppendChild(xCoord); pointNode.AppendChild(yCoord); passwordNode.AppendChild(pointNode); } System.Xml.XmlNode storedDataNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "stored-data", null); foreach (UserInfoTuple userInfo in user.StoredData) { if (userInfo != null) { System.Xml.XmlNode tupleNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "stored-data-tuple", null); System.Xml.XmlNode refNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "reference", null); System.Xml.XmlNode unNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "username", null); System.Xml.XmlNode pwNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "password", null); refNode.InnerText = userInfo.Reference; unNode.InnerText = userInfo.Username; pwNode.InnerText = userInfo.Password; tupleNode.AppendChild(refNode); tupleNode.AppendChild(unNode); tupleNode.AppendChild(pwNode); storedDataNode.AppendChild(tupleNode); } } node.AppendChild(nameNode); node.AppendChild(imageNode); node.AppendChild(faceParamsNode); node.AppendChild(passwordNode); node.AppendChild(storedDataNode); userFile.DocumentElement.AppendChild(node); } else { // Do things or something //XmlNode storedData = node["stored-data"]; System.Xml.XmlNode storedDataNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "stored-data", null); foreach (UserInfoTuple userInfo in user.StoredData) { if (userInfo != null) { System.Xml.XmlNode tupleNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "stored-data-tuple", null); System.Xml.XmlNode refNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "reference", null); System.Xml.XmlNode unNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "username", null); System.Xml.XmlNode pwNode = userFile.CreateNode(System.Xml.XmlNodeType.Element, "password", null); refNode.InnerText = userInfo.Reference; unNode.InnerText = userInfo.Username; pwNode.InnerText = userInfo.Password; tupleNode.AppendChild(refNode); tupleNode.AppendChild(unNode); tupleNode.AppendChild(pwNode); storedDataNode.AppendChild(tupleNode); } } //node["stored-data"] = storedDataNode; node.RemoveChild(node["stored-data"]); node.AppendChild(storedDataNode); } userFile.Save(filename); } catch (Exception exception) { Console.WriteLine("file not found"); } }
private void CopyClick(User user, int itemIdx, StoredDataType type) { String textToCopy = ""; if (user.StoredData.Length > itemIdx) { if (type == StoredDataType.REFERENCE) { textToCopy = user.StoredData[itemIdx].Reference; } else if (type == StoredDataType.USERNAME) { textToCopy = user.StoredData[itemIdx].Username; } else if (type == StoredDataType.PASSWORD) { textToCopy = user.StoredData[itemIdx].Password; } } System.Windows.Clipboard.SetText(textToCopy); }
private void login_Click(object sender, RoutedEventArgs e) { CurrentObjectBag.SLearningNewUser = false; this.currentUser = new User("", "", null, null, null); this.currentUser.name = this.Username.Text; this.isUserNew = false; this.InitialPanel.Visibility = System.Windows.Visibility.Collapsed; this.userNamestackPanel.Visibility = System.Windows.Visibility.Visible; this.AccountButton.Content = "Log in"; }
private void New_Account_Click(object sender, RoutedEventArgs e) { CurrentObjectBag.SLearningNewUser = true; this.currentUser = new User("", "", null, null, null); this.isUserNew = true; this.InitialPanel.Visibility = System.Windows.Visibility.Collapsed; this.userNamestackPanel.Visibility = System.Windows.Visibility.Visible; }
private void home_Click(object sender, RoutedEventArgs e) { if (this.isfaceTrackerOn) { faceTrackingViewer.stopTracking(); } //this.sensor.DepthFrameReady += null; this.sensor.DepthFrameReady -= this.SensorDepthFrameReady; this.sensor.SkeletonFrameReady -= this.SensorSkeletonFrameReady; //this.sensor.SkeletonFrameReady += null; if (gValidator != null) { //gValidator.OnCompletedValidation += null; } this.currentUser = null; this.myImageBox.Source = null; this.Username.Text = ""; faceScanCount = 0; faceScanCounter = -1; this.progressBar1.Value = 0; this.progressBar2.Value = 0; this.progressBar3.Value = 0; this.InitialPanel.Visibility = System.Windows.Visibility.Visible; this.New_Account.Visibility = System.Windows.Visibility.Visible; this.login.Visibility = System.Windows.Visibility.Visible; this.progressBar1.Width = 55; this.progressBar1.Width = 55; this.progressBar1.Width = 55; this.progressBar1.Visibility = System.Windows.Visibility.Visible; this.progressBar2.Visibility = System.Windows.Visibility.Visible; this.progressBar3.Visibility = System.Windows.Visibility.Visible; this.welcomeMassage.Visibility = System.Windows.Visibility.Collapsed; this.byPass.Visibility = System.Windows.Visibility.Collapsed; this.rescan.Visibility = System.Windows.Visibility.Collapsed; this.gestureTracker.Visibility = System.Windows.Visibility.Collapsed; this.scanpanel.Visibility = System.Windows.Visibility.Collapsed; this.RegistrationMassage.Visibility = System.Windows.Visibility.Collapsed; this.userNamestackPanel.Visibility = System.Windows.Visibility.Collapsed; this.ImagePanel.Visibility = System.Windows.Visibility.Collapsed; this.NewReferencePanel.Visibility = System.Windows.Visibility.Collapsed; this.NewUsernamePanel.Visibility = System.Windows.Visibility.Collapsed; this.NewPasswordPanel.Visibility = System.Windows.Visibility.Collapsed; this.LoggedInUI.Visibility = System.Windows.Visibility.Collapsed; //this.NewStoredDataButtonPanel.Visibility = System.Windows.Visibility.Collapsed; //this.StoredDataGridPanel.Visibility = System.Windows.Visibility.Collapsed; //this.StoredDataGrid.Visibility = System.Windows.Visibility.Collapsed; }
private void gValidator_OnCompletedValidation(bool successful) { if (successful) { if (this.isfaceTrackerOn) { faceTrackingViewer.stopTracking(); } this.sensor.DepthFrameReady -= this.SensorDepthFrameReady; this.sensor.SkeletonFrameReady -= this.SensorSkeletonFrameReady; this.currentUser = LoadUser(this.currentUser.name); this.myImageBox.Source = null; this.Username.Text = ""; faceScanCount = 0; faceScanCounter = -1; this.progressBar1.Value = 0; this.progressBar2.Value = 0; this.progressBar3.Value = 0; this.InitialPanel.Visibility = System.Windows.Visibility.Visible; this.New_Account.Visibility = System.Windows.Visibility.Collapsed; this.login.Visibility = System.Windows.Visibility.Collapsed; this.progressBar1.Width = 55; this.progressBar1.Width = 55; this.progressBar1.Width = 55; this.progressBar1.Visibility = System.Windows.Visibility.Collapsed; this.progressBar2.Visibility = System.Windows.Visibility.Collapsed; this.progressBar3.Visibility = System.Windows.Visibility.Collapsed; this.byPass.Visibility = System.Windows.Visibility.Collapsed; this.rescan.Visibility = System.Windows.Visibility.Collapsed; this.gestureTracker.Visibility = System.Windows.Visibility.Collapsed; this.scanpanel.Visibility = System.Windows.Visibility.Collapsed; this.RegistrationMassage.Visibility = System.Windows.Visibility.Collapsed; this.userNamestackPanel.Visibility = System.Windows.Visibility.Collapsed; this.ImagePanel.Visibility = System.Windows.Visibility.Collapsed; this.welcomeMassage.Visibility = System.Windows.Visibility.Visible; if (currentUser != null) { this.welcomeMassage.Text = "Congratulations " + currentUser.name + ". You are now logged in!"; } else { this.welcomeMassage.Text = "Congratulations! You are now logged in!"; } this.NewReferencePanel.Visibility = System.Windows.Visibility.Visible; this.NewUsernamePanel.Visibility = System.Windows.Visibility.Visible; this.NewPasswordPanel.Visibility = System.Windows.Visibility.Visible; this.LoggedInUI.Visibility = System.Windows.Visibility.Visible; if (currentUser != null) { if (currentUser.StoredData != null) { if (currentUser.StoredData[0] != null) { this.NewReferenceNameTextBlock1.Text = currentUser.StoredData[0].Reference; } if (currentUser.StoredData[1] != null) { this.NewReferenceNameTextBlock2.Text = currentUser.StoredData[1].Reference; } } } //this.NewStoredDataButtonPanel.Visibility = System.Windows.Visibility.Visible; //this.StoredDataGridPanel.Visibility = System.Windows.Visibility.Visible; //this.StoredDataGrid.Visibility = System.Windows.Visibility.Visible; } }
public void verifyUser(double[] vals) { try { data.Load("users.xml"); } catch (Exception) { Console.WriteLine("file not found"); } SortedDictionary<String, double> matches = new SortedDictionary<String, double>(); XmlNodeList users = data.GetElementsByTagName("user"); foreach (XmlNode user in users) { double total = 0; //Console.WriteLine(user["name"].InnerText); XmlNode mets = user["face-params"]; for (int i = 0; i < mets.ChildNodes.Count; i++) { XmlNode met = mets.ChildNodes[i]; double mean = Convert.ToDouble(met["mean"].InnerText); double stdev = Convert.ToDouble(met["stdev"].InnerText); double score = getZScore(vals[i], mean, stdev); //Console.WriteLine("Score---------> " + score); if(score >= 1) { total += score; } } //Console.WriteLine(""); try { matches.Add(user["name"].InnerText, total); } catch (Exception e) { } } String bestMatchName = "New User"; double bestMatchVal = 100; foreach (KeyValuePair<String, double> kvp in matches) { Console.WriteLine(kvp.Key + "----------------" + kvp.Value); if (kvp.Value < bestMatchVal) { bestMatchVal = kvp.Value; bestMatchName = kvp.Key; } } if (bestMatchVal <= MAX_DIFF) { Console.WriteLine(bestMatchName); foreach (XmlNode user in users) { if (user["name"].InnerText == bestMatchName) { List<Point2d> tempPts = new List<Point2d>(); XmlNode points = user["points"]; for (int i = 0; i < points.ChildNodes.Count; i++) { XmlNode point = points.ChildNodes[i]; double x = Convert.ToDouble(point["x"].InnerText); double y = Convert.ToDouble(point["y"].InnerText); Point2d tmp = new Point2d(x, y); tempPts.Add(tmp); } XmlNode storedDataXml = user["stored-data"]; UserInfoTuple[] storedData = new UserInfoTuple[Util.NUM_STORED_DATA]; for (int i = 0; i < storedDataXml.ChildNodes.Count; i++) { XmlNode storedDataTuple = storedDataXml.ChildNodes[i]; string reference = Convert.ToString(storedDataTuple["reference"].InnerText); string username = Convert.ToString(storedDataTuple["username"].InnerText); string password = Convert.ToString(storedDataTuple["password"].InnerText); storedData[i] = new UserInfoTuple(reference, username, password); } User current = new User(user["name"].InnerText, user["user-image"].InnerText, tempPts, null, storedData); Console.WriteLine(user["name"].InnerText); Notify(current); return; } } } else { Console.WriteLine("New User"); User cur = new User("", "", null, null, null); Notify(cur); } }
public void addUser(List<List<double>> data) { List<double>[] sorted = new List<double>[7]; for (int h = 0; h < sorted.Length; h++) { sorted[h] = new List<double>(); } for (int i = 0; i < data.Count; i++) { List<double> tmp = data.ElementAt(i); for (int j = 0; j < tmp.Count; j++) { sorted[j].Add(tmp.ElementAt(j)); } } List<Point2d> tempPts = new List<Point2d>(); // calculate mean and standard deviation for (int k = 0; k < sorted.Length; k++) { List<double> tmp = sorted[k]; double average = tmp.Average(); double sumOfSquaresOfDifferences = tmp.Select(val => (val - average) * (val - average)).Sum(); double sd = Math.Sqrt(sumOfSquaresOfDifferences / (tmp.Count - 1)); if (sd < 0.0001) { sd = .00010101; } Point2d tempPoint = new Point2d(average, sd); tempPts.Add(tempPoint); } User cur = new User("", "", null, tempPts, null); Notify(cur); }
private void Notify(User u) { // could be an issue if no one is listening, but there should be a listener by the time this is called if (_onUserRecieved != null) _onUserRecieved(u); }