Package com.libremobileos.yifan.face
Class FaceStorageBackend
- java.lang.Object
-
- com.libremobileos.yifan.face.FaceStorageBackend
-
- Direct Known Subclasses:
DirectoryFaceStorageBackend
,SharedPreferencesFaceStorageBackend
,VolatileFaceStorageBackend
public abstract class FaceStorageBackend extends Object
Store Faces on disk (or in memory, or anywhere else, really). This abstract class already performs error checking, caching and data type conversion for both users and implementations. Creating a new implementation only requires any key-value store that can store Base64-encoded strings. An implementation is required to use this class.
-
-
Constructor Summary
Constructors Constructor Description FaceStorageBackend()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description boolean
delete(String name)
Delete all references to a face.protected abstract boolean
deleteInternal(String name)
Delete all references to a face.boolean
extendRegistered(String rawname, float[] alldata, boolean add)
Adds 1D face model to existing 2D face model to improve accuracy.float[][]
get(String name)
Load 2D face model from storage.protected abstract String
getInternal(String name)
Load 2D face model from storage.Set<String>
getNames()
Get all known facesprotected abstract Set<String>
getNamesInternal()
Get all known facesboolean
register(String rawname, float[] alldata)
Store 1D face model by converting it to 2D and then callingregister(String, float[][])
.
Implementation looks like this:return register(rawname, new float[][] { alldata })
).boolean
register(String rawname, float[][] alldata)
Register/store new face.boolean
register(String rawname, float[][] alldata, boolean replace)
Register/store new face.protected abstract boolean
registerInternal(String name, String data, boolean duplicate)
Register/store new face.
-
-
-
Method Detail
-
getNames
public Set<String> getNames()
Get all known faces- Returns:
Set
of all known faces (names only)
-
register
public boolean register(String rawname, float[][] alldata, boolean replace)
Register/store new face.- Parameters:
rawname
- Name of the face, needs to be unique.alldata
- Face detection model data to store.replace
- Allow replacing an already registered face (based on name). If false and it's still attempted, the method returns false and does nothing.- Returns:
- If registering was successful.
- See Also:
register(String, float[][])
,register(String, float[])
-
register
public boolean register(String rawname, float[][] alldata)
Register/store new face. Callsregister(String, float[][], boolean)
and does not allow replacements.- Parameters:
rawname
- Name of the face, needs to be unique.alldata
- Face detection model data to store.- Returns:
- If registering was successful.
- See Also:
register(String, float[][], boolean)
,register(String, float[])
-
register
public boolean register(String rawname, float[] alldata)
Store 1D face model by converting it to 2D and then callingregister(String, float[][])
.
Implementation looks like this:return register(rawname, new float[][] { alldata })
).- Parameters:
rawname
- Name of the face, needs to be unique.alldata
- 1D face detection model data to store.- Returns:
- If registering was successful.
- See Also:
register(String, float[][], boolean)
,register(String, float[][])
-
extendRegistered
public boolean extendRegistered(String rawname, float[] alldata, boolean add)
Adds 1D face model to existing 2D face model to improve accuracy.- Parameters:
rawname
- Name of the face, needs to be unique.alldata
- 1D face detection model data to storeadd
- If the face doesn't already exist, can we create it?- Returns:
- If registering was successful.
-
get
public float[][] get(String name)
Load 2D face model from storage.- Parameters:
name
- The name of the face to load.- Returns:
- The face model.
-
delete
public boolean delete(String name)
Delete all references to a face.- Parameters:
name
- The face to delete.- Returns:
- If deletion was successful.
-
getNamesInternal
protected abstract Set<String> getNamesInternal()
Get all known faces- Returns:
Set
of all known faces (names only)
-
registerInternal
protected abstract boolean registerInternal(String name, String data, boolean duplicate)
Register/store new face.- Parameters:
name
- Name of the face, needs to be unique.data
- Face detection model data to store.duplicate
- Only true if we are adding a duplicate and want to replace the saved one.- Returns:
- If registering was successful.
-
getInternal
protected abstract String getInternal(String name)
Load 2D face model from storage.- Parameters:
name
- The name of the face to load.- Returns:
- The face model.
-
deleteInternal
protected abstract boolean deleteInternal(String name)
Delete all references to a face.- Parameters:
name
- The face to delete.- Returns:
- If deletion was successful.
-
-