Search code examples
androidface-api

How to Use Microsoft's Face API for Identifying user?


I am doing an android application which capture photo to verify the user. I am trying to create personGroup with few images. But I got this error.

com.microsoft.projectoxford.face.rest.ClientException: Person group ID is invalid.

And my code is,

public fun createPersonGroup(personGroupId: String, personGroupName: String) {
    faceServiceClient.createPersonGroup(personGroupId, personGroupName, null)
}

public fun addPersonToGroup(personGroupId: String, name: String, pathToImages: File) {
    val person = faceServiceClient.createPerson(personGroupId, name, null)
    detectAndRegister(personGroupId, person, pathToImages)
}

private fun detectAndRegister(personGroupId: String, person: CreatePersonResult?, pathToImages: File) {

    for (file in pathToImages.listFiles()) {
        val stream = file.inputStream()
        faceServiceClient.addPersonFace(personGroupId, person!!.personId, stream, null, null)
    }

    trainingAI(personGroupId)
}

private fun trainingAI(personGroupId: String) {
    faceServiceClient.trainPersonGroup(personGroupId)
    var trainingStatus: TrainingStatus? = null

    while (true) {
        trainingStatus = faceServiceClient.getPersonGroupTrainingStatus(personGroupId)
        if (trainingStatus!!.status != TrainingStatus.Status.Running) {
            runOnUiThread { progressDialog.dismiss() }
            break
        }
    }
}

Solution

  • Check that you're doing things in the correct order.

    Create a person group. Add a user to that person group with pictures. Train the person group. Try to identify a picture inside the person group.

    Also like Luis said, check you're not using any invalid characters.