1 #include <avatar_sdk_sample.hpp> 6 #include <android/log.h> 7 #define printf(...) __android_log_print(ANDROID_LOG_DEBUG, "AVATAR_SDK_SAMPLE", __VA_ARGS__) 10 std::vector<std::string> splitString(std::string& str, std::string separator)
12 std::vector<std::string> result;
13 size_t prevPos = 0, pos = 0;
14 while ((pos = str.find(separator, pos)) != std::string::npos)
16 result.push_back(str.substr(prevPos, pos - prevPos));
19 result.push_back(str.substr(prevPos, pos - prevPos));
25 unsigned int haircutsStrSize = 0;
27 std::string haircutsStr(availableHaircuts, haircutsStrSize);
29 std::vector<std::string> haircuts = splitString(haircutsStr,
";");
30 for (
int i = 0; i < haircuts.size(); i++)
32 if (haircuts[i].find(
"generated") != std::string::npos)
38 int generateAvatarInStorage(
AvatarSdkPipelineSubtype pipelineSubtype, std::string inputImagePath, std::string outputDirPath, std::string resourcesPath, ReportProgress progressCallback)
41 int code =
initAvatarSdk(
"Avatar SDK Sample", resourcesPath.c_str());
44 printf(
"Unable to initialize Avatar SDK! \n");
55 std::string generatedHaircutName = findGeneratedHaircutName(pipelineSubtype);
56 params.
addHaircuts(generatedHaircutName.c_str(), generatedHaircutName.size());
61 printf(
"Error occured during avatar generation!\n");
63 printf(
"Avatar was generated!\n");
71 int generateAvatarInMemory(
AvatarSdkPipelineSubtype pipelineSubtype, std::string inputImagePath, std::string resourcesPath, ReportProgress progressCallback)
74 int code =
initAvatarSdk(
"Avatar SDK Sample", resourcesPath.c_str());
77 printf(
"Unable to initialize Avatar SDK! \n");
92 std::string haircutName = findGeneratedHaircutName(pipelineSubtype);
93 params.
addHaircuts(haircutName.c_str(), haircutName.size());
96 unsigned int blendshapesStrSize = 0;
104 printf(
"Avatar was generated!\n");
107 int verticesCount = 0;
116 int textureWidth, textureHeight;
117 const unsigned char* texture =
getAvatarTexture(textureWidth, textureHeight, NULL);
120 int haircutVerticesCount = 0;
121 const float* haircutVertices =
getHaircutVertices(haircutVerticesCount, haircutName.c_str(),
nullptr);
122 printf(
"There are %d vertices for haircut %s stored in memory \n", haircutVerticesCount, haircutName.c_str());
125 int haircutFacesCount = 0;
126 const int* haircutFaces =
getHaircutFaces(haircutFacesCount, haircutName.c_str(),
nullptr);
127 printf(
"There are %d faces for haircut %s stored in memory \n", haircutFacesCount, haircutName.c_str());
130 int haircutTextureWidth, haircutTextureHeight;
131 const unsigned char* haircutTexture =
getHaircutTexture(haircutTextureWidth, haircutTextureHeight, haircutName.c_str(),
nullptr);
134 std::string blendshapeName =
"jawOpen";
135 int blendshapeVerticesCount = 0;
141 if (modelInfoEntry.age == AgePredicted::CHILD)
143 printf(
"Age: Child \n");
145 else if (modelInfoEntry.age == AgePredicted::NOT_CHILD)
147 printf(
"Age: Not child \n");
149 printf(
"Age confidence: %f \n", modelInfoEntry.ageConfidence);
151 printf(
"Predicted race: %d\n", modelInfoEntry.race->predicted);
154 printf(
"Error occured during avatar generation!\n");
163 for (
unsigned int i = 0; i < resourcesList.length; i++)
165 printf(
"%d - %s : %s \n", i, resourcesList.resources[i].name, resourcesList.resources[i].path);
169 int generateAvatarWithParameters(
AvatarSdkPipelineSubtype subtype, std::string inputImagePath, std::string outputDirPath, std::string resourcesPath, ReportProgress progressCallback)
172 int code =
initAvatarSdk(
"Avatar SDK Sample", resourcesPath.c_str());
175 printf(
"Unable to initialize Avatar SDK! \n");
184 avatarParams.
outputMeshFormat = AvatarSdkMeshFormat::AVATAR_SDK_MESH_FORMAT_OBJ;
185 if (subtype == AvatarSdkPipelineSubtype::HEAD_MOBILE)
198 if (subtype == AvatarSdkPipelineSubtype::HEAD_MOBILE)
203 if (subtype == AvatarSdkPipelineSubtype::BUST_MOBILE)
212 unsigned int haircutsStrSize = 0;
214 printf(
"Available haircuts: %s\n", availableHaircuts);
216 unsigned int blendshapesStrSize = 0;
218 printf(
"Available blendshapes: %s\n", availableBlendshapes);
220 avatarParams.
addBlendshapes(availableBlendshapes, blendshapesStrSize);
221 avatarParams.
addHaircuts(availableHaircuts, haircutsStrSize);
226 printf(
"Avatar was generated!\n");
232 if (entry.
age == AgePredicted::CHILD)
234 printf(
"Age: Child \n");
236 else if (entry.
age == AgePredicted::NOT_CHILD)
238 printf(
"Age: Not child \n");
246 printf(
"Predicted race: %d\n", entry.
race->predicted);
252 printf(
"Model's haircuts: \n");
253 printResources(modelHaircuts);
254 printf(
"Model's blendshapes: \n");
255 printResources(modelBlendshapes);
259 printf(
"Error occured getting of model info!\n");
264 printf(
"Unable to generate avatar. Error code: %d", code);
275 int generateCartoonishAvatar(
AvatarSdkPipelineSubtype subtype, std::string inputImagePath, std::string outputDirPath, std::string resourcesPath, ReportProgress progressCallback)
278 int code =
initAvatarSdk(
"Avatar SDK Sample", resourcesPath.c_str());
281 printf(
"Unable to initialize Avatar SDK! \n");
290 avatarParams.
outputMeshFormat = AvatarSdkMeshFormat::AVATAR_SDK_MESH_FORMAT_OBJ;
293 if (subtype == AvatarSdkPipelineSubtype::HEAD_MOBILE)
304 std::string haircutName = findGeneratedHaircutName(subtype);
305 avatarParams.
addHaircuts(haircutName.c_str(), haircutName.size());
310 printf(
"Cartoonsih avatar was generated!\n");
314 printf(
"Unable to generate cartoonish avatar. Error code: %d", code);
bool parametricEyesTexture
Replace eye texture from submitted photo to generated one with sclera and iris colors match the photo...
float ageConfidence
Represents the confidence of age classification with value in the range [0.5, 1] inclusive.
DllExport AvatarSdkResourcesList getAvatarHaircutsList(const char *pathToModelDir)
bool race
Predict person's race from a submitted photo.
bool gender
Predict person's gender from a submitted photo.
bool enhanceLighting
Attempt to make lighting more uniform.
DllExport const float * getAvatarBlendshapeDeltas(const char *blendshapeName, int &verticesCount, const char *pathToModelDir)
DllExport int getAvatarModelInfo(const char *pathToModelDir, AvatarSdkModelInfoEntry &entry)
char * predictedHaircut
A name of the predicted haircut.
DllExport void setEyeScleraColor(unsigned char r, unsigned char g, unsigned char b)
Set eye sclera color.
AvatarSdkPipelineSubtype pipelineSubtype
Type of the avatar.
AvatarSdkMeshFormat outputMeshFormat
Format in which output meshes will be saved.
bool removeSmile
Remove smile in case it is detected on the source photo.
char * outputDirPath
Directory to which the result will be written.
AvatarSdkModelInfo * modelInfo
Computation parameters. The generated data is stored in the model.json file in the output directory...
bool addGlare
Add a glare directly into parametric eye texture Works only when parametricEyesTexture is set...
int lodNumber
Level of Details from 0 to 7 available for the head/mobile subtype.
bool hairColor
Compute average haircut color from a submitted photo.
bool addEyelidShadow
Add an eyelid shadow on top of eye texture. Works only when parametricEyesTexture is set...
bool slightlyCartoonishTexture
Make the model texture looking with a slightly cartoonish effect.
AgePredicted age
Classify a person's age from a submitted photo. Currently possible values are CHILD and NOT_CHILD...
float cartoonishLevel
Level of the cartoon-like stylization in range [0, 1]. Applied only to the "Head 2.0 | head/mobile" pipeline.
bool facialLandmarks68
Compute facial landmarks. Available only for the "head/mobile" subtype.
DllExport const char * getAvailableHaircuts(AvatarSdkPipelineSubtype pipelineSubtype, unsigned int &size)
DllExport void setEyeIrisColor(unsigned char r, unsigned char g, unsigned char b)
Set eye iris color.
DllExport const float * getAvatarVertices(int &verticesCount, const char *pathToModelDir)
char * inputImagePath
Path to the photo in the PNG or JPEG format.
AvatarModifications * avatarModifications
Requested avatar modifications.
bool eyeScleraColor
Compute average eye sclera color from a submitted photo.
DllExport void addBlendshapes(const char *blendshapesList, int size)
Add a list of blendshapes.
DllExport const unsigned char * getAvatarTexture(int &textureWidth, int &textureHeight, const char *pathToModelDir)
bool age
Classify a person's age from a submitted photo.
DllExport int releaseAvatarSdk()
DllExport int generateAvatar(const AvatarSdkParams &avatarParams, ReportProgress reportProgress)
bool eyeIrisColor
Compute average eye iris color from a submitted photo.
DllExport const char * getAvailableBlendshapes(AvatarSdkPipelineSubtype pipelineSubtype, unsigned int &size)
DllExport const double * getAvatarUVMapping(int &facesCount, const char *pathToModelDir)
AvatarSdkColorRgb * skinColor
Average skin color computed from a submitted photo.
DllExport AvatarSdkResourcesList getAvatarBlendshapesList(const char *pathToModelDir)
DllExport const int * getAvatarFaces(int &facesCount, const char *pathToModelDir)
DllExport void setHairColor(unsigned char r, unsigned char g, unsigned char b)
Set hair color.
DllExport void addHaircuts(const char *haircutsList, int size)
Add a list of haircuts.
DllExport const float * getHaircutVertices(int &verticesCount, const char *haircutName, const char *pathToModelDir)
bool curvedBottom
Make the bottom of model bust slightly curved. (Parameter is applicable to bust/mobile models only)...
bool removeGlasses
Attempt to remove glasses on the submitted photo before the actual avatar computation start...
bool skinColor
Compute average skin color from a submitted photo.
RacePredicted * race
Represents a person's race prediction result.
DllExport const int * getHaircutFaces(int &facesCount, const char *haircutName, const char *pathToModelDir)
bool predictHaircut
Predict which haircut from the base and the facegen sets matches best to the submitted photo...
DllExport const unsigned char * getHaircutTexture(int &textureWidth, int &textureHeight, const char *haircutName, const char *pathToModelDir)
DllExport int initAvatarSdk(const char *programName, const char *resourcesPath)