예제 #1
0
        private void CalculateMatch(string username, string keyDescClass)
        {
            try
            {
                string decKeyClass = DecryptText(keyDescClass);

                KeypointsDescriptors kpDescriptors = DeSerializeObject <KeypointsDescriptors>(decKeyClass);

                Matrix <byte>    useDescriptors = kpDescriptors.descriptors;
                VectorOfKeyPoint useKeyPoints   = kpDescriptors.keyPoints;


                using (var db = new BioMexDatabaseEntities1())
                {
                    BFMatcher     matcher = new Emgu.CV.Features2D.BFMatcher(DistanceType.L2);
                    Matrix <byte> mask;

                    User use = (from person in db.Users where ((person.US_USERNAME == username)) select person).FirstOrDefault();

                    var regUser = new UserClass(use.US_USERNAME, use.US_PASSWORD, use.IdealFeatures.FirstOrDefault().IF_PASSWORD_COUNT, use.IdealFeatures.FirstOrDefault().IF_SHIFT_CLASS,
                                                use.IdealFeatures.FirstOrDefault().IF_TYPING_SPEED, 0, DeserializeIntegers(use.IdealFeatures.FirstOrDefault().IF_KEY_ORDER.ToString()).ToArray(), DeserializeIntegers(use.IdealFeatures.FirstOrDefault().IF_KEY_LATENCIES.ToString()).ToArray(),
                                                DeserializeIntegers(use.IdealFeatures.FirstOrDefault().IF_KEY_PRESS_DURATION.ToString()).ToArray(), DeserializeIntegers(use.IdealFeatures.FirstOrDefault().IF_PAIRED_KEYS.ToString()).ToArray());

                    if (use != null && use.US_USERNAME.Equals(username))
                    {
                        matcher.Add(useDescriptors);

                        Matrix <byte>    observedDesc      = DeSerializeObject <Matrix <byte> >(use.Features.FirstOrDefault().FaceFeature.FF_DESCRIPTORS);
                        VectorOfKeyPoint observedKeypoints = DeSerializeObject <VectorOfKeyPoint>(use.Features.FirstOrDefault().FaceFeature.FF_KEY_POINTS);

                        Matrix <int> indices = new Matrix <int>(observedDesc.Rows, 2);

                        VectorOfVectorOfDMatch vectMatch = new VectorOfVectorOfDMatch();

                        using (Matrix <float> Dist = new Matrix <float>(observedDesc.Rows, 2))
                        {
                            matcher.KnnMatch(observedDesc, vectMatch, 2, null);
                            mask = new Matrix <byte>(Dist.Rows, 1);
                            mask.SetValue(255);
                            Features2DToolbox.VoteForUniqueness(vectMatch, 0.8, mask.ToUMat().ToMat(AccessType.Read));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Error while matching");
                System.Diagnostics.Debug.WriteLine(ex.Message);
            }
        }
예제 #2
0
        public void RegisterNewUser(string name, string surname, string username, int age, string password, int passwordCount, int shiftClassification, List <int> passwordSpeed, List <List <int> > keyDowns, List <List <int> > keyLatencies, List <List <int> > pairedKeys, List <List <int> > keyOrder, string keyDescClass)
        {
            EncryptText("");
            using (var db = new BioMexDatabaseEntities1())
            {
                try
                {
                    var newUser = new User
                    {
                        US_NAME           = name,
                        US_SURNAME        = surname,
                        US_PASSWORD       = password,
                        US_USERNAME       = DecryptText(username),
                        US_AGE            = age,
                        US_LAST_LOGGED_IN = DateTime.Now,
                        US_UP_TO_DATE     = true,
                        US_IS_ADMIN       = false,
                    };

                    for (int i = 0; i < 5; i++)
                    {
                        var newFeat = new Feature
                        {
                            FE_PASSWORD_COUNT     = passwordCount,
                            FE_SHIFT_CLASS        = shiftClassification,
                            FE_TIME_TAKEN         = DateTime.Now,
                            FE_TYPING_SPEED       = passwordSpeed[i],
                            FE_KEY_PRESS_DURATION = SerializeIntegers(keyDowns[i]),
                            FE_KEY_LATENCIES      = SerializeIntegers(keyLatencies[i]),
                            FE_KEY_ORDER          = SerializeIntegers(keyOrder[i]),
                            FE_PAIRED_KEYS        = SerializeIntegers(pairedKeys[i]),
                        };

                        newUser.Features.Add(newFeat);
                    }

                    var idealFeat = GetIdealFeature(passwordSpeed, keyDowns, keyLatencies, pairedKeys, keyOrder);

                    idealFeat.IF_PASSWORD_COUNT = passwordCount;
                    idealFeat.IF_SHIFT_CLASS    = shiftClassification;
                    idealFeat.IF_TIME_TAKEN     = DateTime.Now;

                    newUser.IdealFeatures.Add(idealFeat);

                    FaceFeature newFaceFeat = new FaceFeature();

                    //newFaceFeat.FF_DESCRIPTORS = DecryptText(descriptors);
                    //newFaceFeat.FF_KEY_POINTS = DecryptText(keypoints);

                    KeypointsDescriptors builtUpClass = DeSerializeObject <KeypointsDescriptors>(DecryptText(keyDescClass));

                    newFaceFeat.FF_DESCRIPTORS = SerializeObject(builtUpClass.descriptors.ToString());
                    newFaceFeat.FF_KEY_POINTS  = SerializeObject(builtUpClass.keyPoints.ToArray());

                    newUser.Features.FirstOrDefault().FaceFeature = newFaceFeat;



                    db.Users.Add(newUser);
                    db.SaveChanges();
                    System.Diagnostics.Debug.WriteLine("New user successfully added");
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine("Exception caught while registering new user");
                    System.Diagnostics.Debug.WriteLine(ex.Message);
                }
            }
        }