diff --git a/CMakeLists.txt b/CMakeLists.txt index 2b1995a..36480a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.9) # Global settings set(BR_SHARE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/share/openbr") +set(BR_SCRIPTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/scripts") set(CMAKE_AUTOMOC ON) set(CPACK_PACKAGE_NAME "OpenBR") set(CPACK_PACKAGE_VENDOR "OpenBiometrics") @@ -137,6 +138,9 @@ endif() install(FILES CHANGELOG.md LICENSE.txt README.md DESTINATION .) install(DIRECTORY share DESTINATION .) install(DIRECTORY ${BR_THIRDPARTY_SHARE} DESTINATION share) +# install C API Python wrapper +execute_process(COMMAND python -c "import site, sys; sys.stdout.write(site.getsitepackages()[-1])" OUTPUT_VARIABLE PYTHON_SITE_DIR) +install(DIRECTORY ${BR_SCRIPTS_DIR}/brpy DESTINATION ${PYTHON_SITE_DIR}) # Package set(CPACK_PACKAGE_EXECUTABLES "OpenBR" "OpenBR") diff --git a/scripts/brpy/__init__.py b/scripts/brpy/__init__.py new file mode 100644 index 0000000..44c2e5e --- /dev/null +++ b/scripts/brpy/__init__.py @@ -0,0 +1,107 @@ +from ctypes import * + +def _string_args(n): + s = [] + for i in range(n): + s.append(c_char_p) + return s + +def _var_string_args(n): + s = [c_int, POINTER(c_char_p)] + s.extend(_string_args(n)) + return s + +def init_brpy(br_loc='/usr/local/lib/libopenbr.dylib'): + """Takes the ctypes lib object for br and initializes all function inputs and outputs""" + br = cdll.LoadLibrary(br_loc) + plot_args = _var_string_args(1) + [c_bool] + + br.br_about.restype = c_char_p + br.br_cat.argtypes = _var_string_args(1) + br.br_cluster.argtypes = [c_int, POINTER(c_char_p), c_float, c_char_p] + br.br_combine_masks.argtypes = _var_string_args(2) + br.br_compare.argtypes = _string_args(3) + br.br_pairwise_compare.argtypes = _string_args(3) + br.br_convert.argtypes = _string_args(3) + br.br_enroll.argtypes = _string_args(2) + br.br_enroll_n.argtypes = _var_string_args(1) + br.br_eval.argtypes = _string_args(3) + br.br_eval.restype = c_float + br.br_eval_classification.argtypes = _string_args(4) + br.br_eval_clustering.argtypes = _string_args(2) + br.br_eval_detection.argtypes = _string_args(3) + br.br_eval_detection.restype = c_float + br.br_eval_landmarking.argtypes = _string_args(3) + [c_int, c_int] + br.br_eval_landmarking.restype = c_float + br.br_eval_regression.argtypes = _string_args(4) + br.br_fuse.argtypes = _var_string_args(3) + br.br_initialize.argtypes = _var_string_args(1) + br.br_is_classifier.argtypes = [c_char_p] + br.br_is_classifier.restype = c_bool + br.br_make_mask.argtypes = _string_args(3) + br.br_make_pairwise_mask.argtypes = _string_args(3) + br.br_most_recent_message.restype = c_char_p + br.br_objects.argtypes = _string_args(2) + [c_bool] + br.br_objects.restype = c_char_p + br.br_plot.argtypes = plot_args + br.br_plot.restype = c_bool + br.br_plot_detection.argtypes = plot_args + br.br_plot_detection.restype = c_bool + br.br_plot_landmarking.argtypes = plot_args + br.br_plot_landmarking.restype = c_bool + br.br_plot_metadata.argtypes = plot_args + br.br_plot_metadata.restype = c_bool + br.br_progress.restype = c_float + br.br_read_pipe.argtypes = [c_char_p, POINTER(c_int), POINTER(POINTER(c_char_p))] + br.br_scratch_path.restype = c_char_p + br.br_sdk_path.restype = c_char_p + br.br_get_header.argtypes = [c_char_p, POINTER(c_char_p), POINTER(c_char_p)] + br.br_set_header.argtypes = _string_args(3) + br.br_set_property.argtypes = _string_args(2) + br.br_time_remaining.restype = c_int + br.br_train.argtypes = _string_args(2) + br.br_train_n.argtypes = _var_string_args(1) + br.br_version.restype = c_char_p + br.br_slave_process.argtypes = [c_char_p] + br.br_load_img.argtypes = [c_char_p, c_int] + br.br_load_img.restype = c_void_p + br.br_unload_img.argtypes = [c_void_p] + br.br_unload_img.restype = POINTER(c_ubyte) + br.br_template_list_from_buffer.argtypes = [c_char_p, c_int] + br.br_template_list_from_buffer.restype = c_void_p + br.br_free_template.argtypes = [c_void_p] + br.br_free_template_list.argtypes = [c_void_p] + br.br_free_output.argtypes = [c_void_p] + br.br_img_rows.argtypes = [c_void_p] + br.br_img_rows.restype = c_int + br.br_img_cols.argtypes = [c_void_p] + br.br_img_cols.restype = c_int + br.br_img_channels.argtypes = [c_void_p] + br.br_img_channels.restype = c_int + br.br_img_is_empty.argtypes = [c_void_p] + br.br_img_is_empty.restype = c_bool + br.br_get_filename.argtypes = [c_void_p] + br.br_get_filename.restype = c_char_p + br.br_set_filename.argtypes = [c_void_p, c_char_p] + br.br_get_metadata_string.argtypes = [c_void_p, c_char_p] + br.br_get_metadata_string.restype = c_char_p + br.br_enroll_template.argtypes = [c_void_p] + br.br_enroll_template.restype = c_void_p + br.br_enroll_template_list.argtypes = [c_void_p] + br.br_enroll_template_list.restype = c_void_p + br.br_compare_template_lists.argtypes = [c_void_p, c_void_p] + br.br_compare_template_lists.restype = c_void_p + br.br_get_matrix_output_at.argtypes = [c_void_p, c_int, c_int] + br.br_get_matrix_output_at.restype = c_float + br.br_get_template.argtypes = [c_void_p, c_int] + br.br_get_template.restype = c_void_p + br.br_num_templates.argtypes = [c_void_p] + br.br_num_templates.restype = c_int + br.br_make_gallery.argtypes = [c_char_p] + br.br_make_gallery.restype = c_void_p + br.br_load_from_gallery.argtypes = [c_void_p] + br.br_load_from_gallery.restype = c_void_p + br.br_add_to_gallery.argtypes = [c_void_p, c_void_p] + br.br_close_gallery.argtypes = [c_void_p] + + return br