Commit 62f9e899dfa49eb874039ea32ea4188e8b453a4a
1 parent
af8b416f
Add a little python module to wrap br with ctypes, install to site-pacakges in cmakelists
Showing
2 changed files
with
111 additions
and
0 deletions
CMakeLists.txt
| ... | ... | @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 2.8.9) |
| 3 | 3 | |
| 4 | 4 | # Global settings |
| 5 | 5 | set(BR_SHARE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/share/openbr") |
| 6 | +set(BR_SCRIPTS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/scripts") | |
| 6 | 7 | set(CMAKE_AUTOMOC ON) |
| 7 | 8 | set(CPACK_PACKAGE_NAME "OpenBR") |
| 8 | 9 | set(CPACK_PACKAGE_VENDOR "OpenBiometrics") |
| ... | ... | @@ -137,6 +138,9 @@ endif() |
| 137 | 138 | install(FILES CHANGELOG.md LICENSE.txt README.md DESTINATION .) |
| 138 | 139 | install(DIRECTORY share DESTINATION .) |
| 139 | 140 | install(DIRECTORY ${BR_THIRDPARTY_SHARE} DESTINATION share) |
| 141 | +# install C API Python wrapper | |
| 142 | +execute_process(COMMAND python -c "import site, sys; sys.stdout.write(site.getsitepackages()[-1])" OUTPUT_VARIABLE PYTHON_SITE_DIR) | |
| 143 | +install(DIRECTORY ${BR_SCRIPTS_DIR}/brpy DESTINATION ${PYTHON_SITE_DIR}) | |
| 140 | 144 | |
| 141 | 145 | # Package |
| 142 | 146 | set(CPACK_PACKAGE_EXECUTABLES "OpenBR" "OpenBR") | ... | ... |
scripts/brpy/__init__.py
0 → 100644
| 1 | +from ctypes import * | |
| 2 | + | |
| 3 | +def _string_args(n): | |
| 4 | + s = [] | |
| 5 | + for i in range(n): | |
| 6 | + s.append(c_char_p) | |
| 7 | + return s | |
| 8 | + | |
| 9 | +def _var_string_args(n): | |
| 10 | + s = [c_int, POINTER(c_char_p)] | |
| 11 | + s.extend(_string_args(n)) | |
| 12 | + return s | |
| 13 | + | |
| 14 | +def init_brpy(br_loc='/usr/local/lib/libopenbr.dylib'): | |
| 15 | + """Takes the ctypes lib object for br and initializes all function inputs and outputs""" | |
| 16 | + br = cdll.LoadLibrary(br_loc) | |
| 17 | + plot_args = _var_string_args(1) + [c_bool] | |
| 18 | + | |
| 19 | + br.br_about.restype = c_char_p | |
| 20 | + br.br_cat.argtypes = _var_string_args(1) | |
| 21 | + br.br_cluster.argtypes = [c_int, POINTER(c_char_p), c_float, c_char_p] | |
| 22 | + br.br_combine_masks.argtypes = _var_string_args(2) | |
| 23 | + br.br_compare.argtypes = _string_args(3) | |
| 24 | + br.br_pairwise_compare.argtypes = _string_args(3) | |
| 25 | + br.br_convert.argtypes = _string_args(3) | |
| 26 | + br.br_enroll.argtypes = _string_args(2) | |
| 27 | + br.br_enroll_n.argtypes = _var_string_args(1) | |
| 28 | + br.br_eval.argtypes = _string_args(3) | |
| 29 | + br.br_eval.restype = c_float | |
| 30 | + br.br_eval_classification.argtypes = _string_args(4) | |
| 31 | + br.br_eval_clustering.argtypes = _string_args(2) | |
| 32 | + br.br_eval_detection.argtypes = _string_args(3) | |
| 33 | + br.br_eval_detection.restype = c_float | |
| 34 | + br.br_eval_landmarking.argtypes = _string_args(3) + [c_int, c_int] | |
| 35 | + br.br_eval_landmarking.restype = c_float | |
| 36 | + br.br_eval_regression.argtypes = _string_args(4) | |
| 37 | + br.br_fuse.argtypes = _var_string_args(3) | |
| 38 | + br.br_initialize.argtypes = _var_string_args(1) | |
| 39 | + br.br_is_classifier.argtypes = [c_char_p] | |
| 40 | + br.br_is_classifier.restype = c_bool | |
| 41 | + br.br_make_mask.argtypes = _string_args(3) | |
| 42 | + br.br_make_pairwise_mask.argtypes = _string_args(3) | |
| 43 | + br.br_most_recent_message.restype = c_char_p | |
| 44 | + br.br_objects.argtypes = _string_args(2) + [c_bool] | |
| 45 | + br.br_objects.restype = c_char_p | |
| 46 | + br.br_plot.argtypes = plot_args | |
| 47 | + br.br_plot.restype = c_bool | |
| 48 | + br.br_plot_detection.argtypes = plot_args | |
| 49 | + br.br_plot_detection.restype = c_bool | |
| 50 | + br.br_plot_landmarking.argtypes = plot_args | |
| 51 | + br.br_plot_landmarking.restype = c_bool | |
| 52 | + br.br_plot_metadata.argtypes = plot_args | |
| 53 | + br.br_plot_metadata.restype = c_bool | |
| 54 | + br.br_progress.restype = c_float | |
| 55 | + br.br_read_pipe.argtypes = [c_char_p, POINTER(c_int), POINTER(POINTER(c_char_p))] | |
| 56 | + br.br_scratch_path.restype = c_char_p | |
| 57 | + br.br_sdk_path.restype = c_char_p | |
| 58 | + br.br_get_header.argtypes = [c_char_p, POINTER(c_char_p), POINTER(c_char_p)] | |
| 59 | + br.br_set_header.argtypes = _string_args(3) | |
| 60 | + br.br_set_property.argtypes = _string_args(2) | |
| 61 | + br.br_time_remaining.restype = c_int | |
| 62 | + br.br_train.argtypes = _string_args(2) | |
| 63 | + br.br_train_n.argtypes = _var_string_args(1) | |
| 64 | + br.br_version.restype = c_char_p | |
| 65 | + br.br_slave_process.argtypes = [c_char_p] | |
| 66 | + br.br_load_img.argtypes = [c_char_p, c_int] | |
| 67 | + br.br_load_img.restype = c_void_p | |
| 68 | + br.br_unload_img.argtypes = [c_void_p] | |
| 69 | + br.br_unload_img.restype = POINTER(c_ubyte) | |
| 70 | + br.br_template_list_from_buffer.argtypes = [c_char_p, c_int] | |
| 71 | + br.br_template_list_from_buffer.restype = c_void_p | |
| 72 | + br.br_free_template.argtypes = [c_void_p] | |
| 73 | + br.br_free_template_list.argtypes = [c_void_p] | |
| 74 | + br.br_free_output.argtypes = [c_void_p] | |
| 75 | + br.br_img_rows.argtypes = [c_void_p] | |
| 76 | + br.br_img_rows.restype = c_int | |
| 77 | + br.br_img_cols.argtypes = [c_void_p] | |
| 78 | + br.br_img_cols.restype = c_int | |
| 79 | + br.br_img_channels.argtypes = [c_void_p] | |
| 80 | + br.br_img_channels.restype = c_int | |
| 81 | + br.br_img_is_empty.argtypes = [c_void_p] | |
| 82 | + br.br_img_is_empty.restype = c_bool | |
| 83 | + br.br_get_filename.argtypes = [c_void_p] | |
| 84 | + br.br_get_filename.restype = c_char_p | |
| 85 | + br.br_set_filename.argtypes = [c_void_p, c_char_p] | |
| 86 | + br.br_get_metadata_string.argtypes = [c_void_p, c_char_p] | |
| 87 | + br.br_get_metadata_string.restype = c_char_p | |
| 88 | + br.br_enroll_template.argtypes = [c_void_p] | |
| 89 | + br.br_enroll_template.restype = c_void_p | |
| 90 | + br.br_enroll_template_list.argtypes = [c_void_p] | |
| 91 | + br.br_enroll_template_list.restype = c_void_p | |
| 92 | + br.br_compare_template_lists.argtypes = [c_void_p, c_void_p] | |
| 93 | + br.br_compare_template_lists.restype = c_void_p | |
| 94 | + br.br_get_matrix_output_at.argtypes = [c_void_p, c_int, c_int] | |
| 95 | + br.br_get_matrix_output_at.restype = c_float | |
| 96 | + br.br_get_template.argtypes = [c_void_p, c_int] | |
| 97 | + br.br_get_template.restype = c_void_p | |
| 98 | + br.br_num_templates.argtypes = [c_void_p] | |
| 99 | + br.br_num_templates.restype = c_int | |
| 100 | + br.br_make_gallery.argtypes = [c_char_p] | |
| 101 | + br.br_make_gallery.restype = c_void_p | |
| 102 | + br.br_load_from_gallery.argtypes = [c_void_p] | |
| 103 | + br.br_load_from_gallery.restype = c_void_p | |
| 104 | + br.br_add_to_gallery.argtypes = [c_void_p, c_void_p] | |
| 105 | + br.br_close_gallery.argtypes = [c_void_p] | |
| 106 | + | |
| 107 | + return br | ... | ... |