Ejemplo n.º 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);
        }
Ejemplo n.º 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;
 }
Ejemplo n.º 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);
        }
Ejemplo n.º 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);
     }
 }
Ejemplo n.º 5
0
 public FaceDatabaseDeserializer(IFaceInfo <TTemplate> faceInfoBaseInstance, DictionaryFaceDatabase <TTemplate> db)
 {
     _faceInfoBaseInstance = faceInfoBaseInstance;
     _db = db;
 }
Ejemplo n.º 6
0
 public bool TryGetValue(int id, out IFaceInfo <TTemplate> faceInfo)
 {
     return(_storedFaces.TryGetValue(id, out faceInfo));
 }