-
Notifications
You must be signed in to change notification settings - Fork 0
Home
mchalil edited this page Dec 27, 2021
·
1 revision
t_privid_face_handle FHE_init(int option); // create one instance of privid_face object
int is_valid(t_privid_face_handle h, // handle returned by FHE_init
bool isContextEnroll, // true for Enroll false for prediction
uint8_t* image, // image byte array
//int im_size, // image byte array size in bytes
int width, // image horizontal pixel count
int height, // image vertical pixel count
uint8_t* cropped_image_out
);
int FHE_enroll_predict(t_privid_face_handle h,
bool isContextEnroll,
uint8_t* p_buffer_images_in, int im_count, int im_size, int im_width, int im_height,
float* p_buffer_embeddings_out, // returns the embedding of size 128
bool shouldRemoveBadEmbeddings, // set true if bad embedding removal to be enabled
uint8_t* augmentations_out // set a valid pointer of enough size to enable augmented images. pass NULL if no to be saved.
);
int FHE_compare_embeddings(t_privid_face_handle h,
int biometric_type, // ePiDataTypeFaceMask or ePiDataTypeFace
float* p_buffer_embeddings_A, int count_A, // pointer to embeddings and the total embeddings
float* p_buffer_embeddings_B, int count_B, // -do-
float fudge_factor // todo
);
int FHE_compare_files(t_privid_face_handle h,
int biometric_type,
uint8_t* p_buffer_files_A, int count_A, // image byte pointer and size
uint8_t* p_buffer_files_B, int count_B, // -do-
int im_size, int im_width, int im_height, // size in bytes, width and height
float fudge_factor //
);
int FHE_configure_url( t_privid_face_handle h,
int conf_param_id, // id_conf_url_endpoint_predict to configure endpoint URL for predict/enroll
char* param, // pointer to string
int32_t paramLen // length of the string
);
int tst_is_valid(t_privid_face_handle handle, std::string image_name_in)
{
Mat srcImage = imread(image_name_in);
if (!srcImage.data) {
return 1;
}
int width = srcImage.size().width;
int height = srcImage.size().height;
std::cout << "width = " << width << std::endl;
std::cout << "height = " << height << std::endl;
matToBytes(srcImage, input_img_buffer);
bool isContextEnroll = false;
int valid_flag = is_valid(handle, isContextEnroll, input_img_buffer, width, height, NULL);
std::cout << "result, valid_flag = " << valid_flag << std::endl;
return 0;
}int tst_compare(t_privid_face_handle handle, std::string image_a, std::string image_b)
{
int ret = 0;
std::cout << " Comaparing Image " << image_a << " & Image "<< image_b << std::endl;
Mat srcImageA = imread(image_a);
if (!srcImageA.data) {
return -1;
}
int widthA = srcImageA.size().width;
int heightA = srcImageA.size().height;
std::cout << "widthA = " << widthA << std::endl;
std::cout << "heightA = " << heightA << std::endl;
matToBytes(srcImageA, input_img_buffer);
Mat srcImageB = imread(image_b);
if (!srcImageB.data) {
return -2;
}
int widthB = srcImageB.size().width;
int heightB = srcImageB.size().height;
if(heightA != heightB){
return -3;
}
if(widthA != widthB){
return -4;
}
std::cout << "widthB = " << widthB << std::endl;
std::cout << "heightB = " << heightB << std::endl;
matToBytes(srcImageB, input_img_bufferB);
int im_count = 1;
int im_size = im_count*widthA*heightA*4;
float fudge_factor = 0.1f;
ret = FHE_compare_files(handle,
ePiDataTypeFaceMask,
input_img_buffer,
im_count,
input_img_bufferB,
im_count,
im_size,
widthA,
heightA,
fudge_factor);
return ret;
}int main( int argc, char** argv )
{
int option = 0;
float so_ver = get_version();
std::cout << "testing so in C, ver = " << so_ver << std::endl;
int embedding_length = spl_image_embedding_length();
float image_embedding_ver = spl_image_embedding_get_ver();
std::cout << "embedding_length = " << embedding_length << std::endl;
std::cout << "image_embedding_ver = " << image_embedding_ver << std::endl;
t_privid_face_handle handle = FHE_init(option);
if(argc == 1) {
tst_is_valid (handle, "a1.png");
tst_enroll(handle, ".");
tst_predict(handle, ".");
}
if(argc == 2) {
tst_is_valid (handle, argv[1]);
img_enroll(handle, argv[1]);
img_predict(handle, argv[2]);
}
if(argc == 3) {
tst_compare (handle, argv[1], argv[2]);
}
FHE_close(handle);
std::cout << "ok" << std::endl;
return 0;
}
##