Title: | An Interface for Face Recognition |
---|---|
Description: | Provides an interface to the 'Kairos' Face Recognition API <https://kairos.com/face-recognition-api>. The API detects faces in images and returns estimates for demographics. |
Authors: | Carsten Schwemmer [aut, cre] |
Maintainer: | Carsten Schwemmer <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.0 |
Built: | 2024-10-30 03:14:46 UTC |
Source: | https://github.com/cschwem2er/facerec |
Detect faces in an input image and return annotations from the 'Kairos' API.
detect(image, min_head_scale = 0.015)
detect(image, min_head_scale = 0.015)
image |
An image of file type 'JPG', 'PNG', or 'BMP'.
Can either be an url string or a local image processed with |
min_head_scale |
Set the ratio of the smallest face to look for in the input image. Accepts a value between .015 (1:64 scale) and .5 (1:2 scale). |
A data frame with annotations for each detected face.
facerec_init() # one image finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' faces <- detect(image = finn_image) # multiple images sw_image <- 'https://upload.wikimedia.org/wikipedia/en/8/82/Leiadeathstar.jpg' padme_image <- 'https://upload.wikimedia.org/wikipedia/en/e/ee/Amidala.png' faces <- c(finn_image, sw_image, padme_image) %>% purrr::map(detect) %>% dplyr::bind_rows()
facerec_init() # one image finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' faces <- detect(image = finn_image) # multiple images sw_image <- 'https://upload.wikimedia.org/wikipedia/en/8/82/Leiadeathstar.jpg' padme_image <- 'https://upload.wikimedia.org/wikipedia/en/e/ee/Amidala.png' faces <- c(finn_image, sw_image, padme_image) %>% purrr::map(detect) %>% dplyr::bind_rows()
Enroll face in an input image to a gallery and assign a subject id.
enroll(image, subject_id, gallery, min_head_scale = 0.015)
enroll(image, subject_id, gallery, min_head_scale = 0.015)
image |
An image of file type 'JPG', 'PNG', or 'BMP'.
Can either be an url string or a local image processed with |
subject_id |
A string containing the id to assign for the person in the enrolled image. |
gallery |
A string containing the name of the gallery in which the image will be enrolled. |
min_head_scale |
Set the ratio of the smallest face to look for in the input image. Accepts a value between .015 (1:64 scale) and .5 (1:2 scale). |
A data frame with annotations for the enrolled image.
facerec_init() finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars')
facerec_init() finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars')
Initializes the authorization credentials for the 'Kairos' Face Recognition API.
Needs to be called before using any other functions of facerec
and requires kairos_id
and kairos_key
as environment variables.
facerec_init()
facerec_init()
nothing.
## Not run: Sys.setenv(kairos_id = "Your Kairos API id") Sys.setenv(kairos_key = "Your Kairos API key") facerec_init() ## End(Not run)
## Not run: Sys.setenv(kairos_id = "Your Kairos API id") Sys.setenv(kairos_key = "Your Kairos API key") facerec_init() ## End(Not run)
Returns identifiers for all galleries associated with a 'Kairos' application.
get_galleries()
get_galleries()
A vector of gallery id's.
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' first_gallery <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') second_gallery <- enroll(image = finn_image, subject_id = 'finn', gallery = 'more_starwars') # get_galleries get_galleries()
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' first_gallery <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') second_gallery <- enroll(image = finn_image, subject_id = 'finn', gallery = 'more_starwars') # get_galleries get_galleries()
Returns all subject id's associated with a gallery.
get_gallery_subjects(gallery)
get_gallery_subjects(gallery)
gallery |
The gallery in which the subjects are enrolled. |
A vector of subject id's
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') # view subjects get_gallery_subjects(gallery = 'starwars')
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') # view subjects get_gallery_subjects(gallery = 'starwars')
Prepares a local image for an upload the 'Kairos' API via detect
,
enroll
, recognize
and verify
.
prep_image(img_file)
prep_image(img_file)
img_file |
Path to an image of file type 'JPG', 'PNG', or 'BMP'. |
The prepared image object.
facerec_init() # download example image finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' temp_img_path <- tempfile(fileext = '.png') download.file(finn_image, temp_img_path, mode = 'wb', quiet = TRUE) # prepare image finn_local <- prep_image(temp_img_path) # use prepared image faces <- detect(image = finn_local)
facerec_init() # download example image finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' temp_img_path <- tempfile(fileext = '.png') download.file(finn_image, temp_img_path, mode = 'wb', quiet = TRUE) # prepare image finn_local <- prep_image(temp_img_path) # use prepared image faces <- detect(image = finn_local)
Recognize faces in an image and return the most likely matches from a gallery.
recognize(image, gallery, min_head_scale = 0.015, threshold = 0.6, max_num_results = 10, show_candidate_images = TRUE)
recognize(image, gallery, min_head_scale = 0.015, threshold = 0.6, max_num_results = 10, show_candidate_images = TRUE)
image |
An image of file type JPG, PNG, or BMP.
Can either be an url string or a local image processed with |
gallery |
A string containing the name of the gallery in which the image will be enrolled. |
min_head_scale |
Set the ratio of the smallest face to look for in the input image. Accepts a value between .015 (1:64 scale) and .5 (1:2 scale). |
threshold |
Likelihood (between 0 and 1) used to determine a valid facial match. Defaults to 0.6. |
max_num_results |
The maximum number of potential matches that are returned. Defaults to 10. |
show_candidate_images |
Whether to return temporary URLs for each potential match. Defaults to TRUE. |
A dataframe with the potential matches for the input image. The likelihood of matches is given in column confidence
.
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' padme_image <- 'https://upload.wikimedia.org/wikipedia/en/e/ee/Amidala.png' finn_face <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') padme_face <- enroll(image = padme_image, subject_id = 'padme', gallery = 'starwars') # recognize finn_2 <- 'https://upload.wikimedia.org/wikipedia/commons/b/b6/John_Boyega_by_Gage_Skidmore.jpg' finn_rec <- recognize(image = finn_2, gallery = 'starwars')
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' padme_image <- 'https://upload.wikimedia.org/wikipedia/en/e/ee/Amidala.png' finn_face <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') padme_face <- enroll(image = padme_image, subject_id = 'padme', gallery = 'starwars') # recognize finn_2 <- 'https://upload.wikimedia.org/wikipedia/commons/b/b6/John_Boyega_by_Gage_Skidmore.jpg' finn_rec <- recognize(image = finn_2, gallery = 'starwars')
Removes a gallery and all included subjects.
remove_gallery(gallery)
remove_gallery(gallery)
gallery |
The name of the gallery to be removed. |
nothing.
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') # remove gallery remove_gallery(gallery = 'starwars')
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') # remove gallery remove_gallery(gallery = 'starwars')
Removes a subject from a gallery.
remove_subject(subject_id, gallery)
remove_subject(subject_id, gallery)
subject_id |
The subject id for the subject to be removed. |
gallery |
The name of the gallery in which the subject is enrolled. |
nothing.
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') # remove subject remove_subject(subject_id = 'finn', gallery = 'starwars')
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') # remove subject remove_subject(subject_id = 'finn', gallery = 'starwars')
Verify whether face in an input image belongs to a subject in a gallery.
verify(image, subject_id, gallery)
verify(image, subject_id, gallery)
image |
An image of file type 'JPG', 'PNG', or 'BMP'.
Can either be an url string or a local image processed with |
subject_id |
A string containing the id for the person in the gallery to be verified. |
gallery |
A string containing the name of the gallery in which the subject will be verified. |
A data frame with the verification annotations for the input image. The likelihood of a match is given in column confidence
.
facerec_init() # enroll padme_image <- 'https://upload.wikimedia.org/wikipedia/en/e/ee/Amidala.png' padme_face <- enroll(image = padme_image, subject_id = 'padme', gallery = 'starwars') # verify amidala_img <- 'https://upload.wikimedia.org/wikipedia/it/5/5e/Padm%C3%A9_Amidala.png' verified <- verify(image = amidala_img, subject_id = 'padme', gallery = 'starwars')
facerec_init() # enroll padme_image <- 'https://upload.wikimedia.org/wikipedia/en/e/ee/Amidala.png' padme_face <- enroll(image = padme_image, subject_id = 'padme', gallery = 'starwars') # verify amidala_img <- 'https://upload.wikimedia.org/wikipedia/it/5/5e/Padm%C3%A9_Amidala.png' verified <- verify(image = amidala_img, subject_id = 'padme', gallery = 'starwars')
Returns all face id's for each image enrolled for a given subject in a gallery.
view_subject(subject_id, gallery)
view_subject(subject_id, gallery)
subject_id |
The subject id for which to return all face id's. |
gallery |
The gallery in which the subject is enrolled. |
A dataframe with face id's and enrollment timestamps associated with the input subject.
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') # view subject view_subject(subject_id = 'finn', gallery = 'starwars')
facerec_init() # enroll finn_image <- 'https://upload.wikimedia.org/wikipedia/en/2/2a/Finn-Force_Awakens_%282015%29.png' finn_enroll <- enroll(image = finn_image, subject_id = 'finn', gallery = 'starwars') # view subject view_subject(subject_id = 'finn', gallery = 'starwars')