Example #1
0
        public DictionaryFaceDatabase(IFaceInfo <TTemplate> baseInstance = null, IEnumerable <KeyValuePair <int, IFaceInfo <TTemplate> > > initialDb = null)
        {
            if (baseInstance == null)
            {
                // if no IFaceInfo base instance is supplied, find a suitable type using reflection
                var firstType = (from t in Assembly.GetExecutingAssembly().GetExportedTypes()
                                 where !t.IsAbstract && !t.IsInterface && typeof(IFaceInfo <TTemplate>).IsAssignableFrom(t) && t.GetConstructor(Type.EmptyTypes) != null
                                 select t)
                                .FirstOrDefault();

                if (firstType != null)
                {
                    _baseFaceInfo = (IFaceInfo <TTemplate>)Activator.CreateInstance(firstType);
                }
                else
                {
                    throw new ApplicationException($"No suitable class implementing {typeof(IFaceInfo<TTemplate>)} found");
                }
            }
            else
            {
                _baseFaceInfo = baseInstance;
            }

            _storedFaces = initialDb == null
                ? new ConcurrentDictionary <int, IFaceInfo <TTemplate> >()
                : new ConcurrentDictionary <int, IFaceInfo <TTemplate> >(initialDb);
        }
Example #2
0
 public Match(int faceId, float similarity, FaceSnapshot <TTemplate> snapshot, IFaceInfo <TTemplate> faceInfo, bool isValid = true)
 {
     FaceId     = faceId;
     Similarity = similarity;
     Snapshot   = snapshot;
     FaceInfo   = faceInfo;
     IsValid    = isValid;
 }
Example #3
0
        /// <summary>
        /// Will do nothing if a face the same <paramref name="id"/> is already in the database
        /// </summary>
        /// <param name="info"></param>
        /// <param name="id"></param>
        /// <returns><c>true</c> if successful</returns>
        public bool TryAddNewFace(int id, IFaceInfo <TTemplate> info)
        {
            bool ret = _storedFaces.TryAdd(id, info);

            if (ret)
            {
                UpdateNextId(id);
            }

            return(ret);
        }
Example #4
0
 public void Add(int id, IFaceInfo <TTemplate> faceInfo)
 {
     if (_storedFaces.TryGetValue(id, out var targetFaceInfo))
     {
         targetFaceInfo.Merge(faceInfo);
     }
     else
     {
         _storedFaces[id] = faceInfo;
         UpdateNextId(id);
     }
 }
Example #5
0
 public FaceDatabaseDeserializer(IFaceInfo <TTemplate> faceInfoBaseInstance, DictionaryFaceDatabase <TTemplate> db)
 {
     _faceInfoBaseInstance = faceInfoBaseInstance;
     _db = db;
 }
Example #6
0
 public bool TryGetValue(int id, out IFaceInfo <TTemplate> faceInfo)
 {
     return(_storedFaces.TryGetValue(id, out faceInfo));
 }