Persons
Persons are people you would like to recognize/verify using our API.
You can use the API to add persons to the database, group them into collections, and manage them later.
Create a Person
Let's get started with creating a person:
PersonBase personbase;
personbase.name = "varun";
Personbase.images = {“c:\\images\\varun.jpg”};
Person person;
person = sdk.persons.create(personbase);
Here, we have initialized the person object with a name and the path to an image. In addition to a path to an image, you could also have passed in an image in the OpenCV's Mat
format.
personbase.cv_images = {image_1,image_2};
Images can be loaded in both methods to same object.
We now have a created Person.
A person has the following class properties listed below:
name
- mandatory name of the person (we used this while creating the person)images
- at least 1 and a maximum of 3 images of the person (we used one image)id
- if specified, the system uses this as the id of the person. If unspecified, the system uses a unique identifier.gender
- the gender of the persondate_of_birth
- the person's date of birthnationality
- the person's nationalitycollections
- a list of collections that the person belongs tonotes
- any additional notes about the person
List Persons
Now that we have created a Person let's list all persons (as we did with collections).
Options options;
PersonCount persons= sdk.persons.list(options);
This should return an persons
object of type PersonCount
. The count
attribute of the object indicates the number of persons and the person
attribute of the objects is a vector of person object(s) with particulars such as name
and description
.
Filtering Persons
In the previous example, we called sdk.persons.list()
without specifying any qualifiers.
Like in collections, we can call sdk.persons.list()
with additional parameters that determine what results will be returned.
Options options;
options.skip = 0;
options.take = 5;
options.search = “Varun”;
options.order = SortOrder::ASCENDING;
options.order_by = Order_by::CREATE_DATE;
PersonCount persons= sdk.persons.list(options);
As with collections, you can choose a sort order
, a column to order the results by order_by
, a search
string, and take
and skip
parameters to help you implement paging.
Updating a Person
You can update a Person either after creating one, or after getting one:
Create:
Person person;
PersonBase personbase;
personbase.name = "varun";
Personbase.images ={“c:\\images\\varun.jpg”};
person = sdk.persons.create(personbase);
Get:
Person my_person = sdk.persons.get(person.id);
As long as my_person is a valid reference to a person, you can update it like so:
my_person.name = "Speedy Gonzalves";
my_person = sdk.persons.update(my_person);
Updating the images of a Person
To update the images of a person, you can set the images property:
my_person.name = "Speedy Gonzalves";
my_person.images = {"c:\\images\\varun1.jpg"};
my_person = sdk.persons.update(my_person);
Alternatively, the OpenCV Mat
object can be added by
my_person.cv_image = { my_image };
If you retrieved the person using sdk.persons.get(my_person.id)
, then all images should be set in one go.
You should NOT do the following:
my_person.images = {my_person.thumbnail[0].save_jpeg(“c:\\output.jpg”)};
Doing the above will mean that the first image is actually a thumbnail from the server - which is smaller than 224x224 pixels, and should not be sent to the server again. Using new, full size images to update the person's images is the intended way to use this SDK.
Adding a Person to a Collection
To add a Person to a Collection, you can specify the Collection in the collections
list of the person during a create, or update operation.
During creation:
Collection my_collection = sdk.collections.get(mycollection.id);
personbase.name = "varun";
personbase.images ={“c:\\images\\varun.jpg”};
personbase.collection.push_back(my_collection);
person = sdk.persons.create(personbase);
During update:
Collection my_collection = sdk.collections.get(mycollection.id);
person = sdk.persons.get(my_person.id);
person.collections.push_back(my_collection);
person = sdk.persons.update(person);
Deleting multiple Person objects at once
If you know a series of id
to delete, you can delete the multiple persons at once in this manner:
UpdatePersonsRequest update_persons_request;
update_persons_request.action = Action.DEL;
update_persons_request.ids = {my_person.id};
std::vector<std::string> result = sdk.persons.update_persons(update_persons_request);
Deleting a specific Person
If you know the id
of a person, you can delete the person like so:
string deleted_id = sdk.persons.delete_person(person.id);