Commit afe4dc93e4f8c9b67148f27f57f00cac9a01d43d
1 parent
a4c0ddde
Update brpy with string_management changes to C API and make string functions more Pythonic
Showing
1 changed file
with
28 additions
and
8 deletions
scripts/brpy/__init__.py
| ... | ... | @@ -12,6 +12,14 @@ def _var_string_args(n): |
| 12 | 12 | s.extend(_string_args(n)) |
| 13 | 13 | return s |
| 14 | 14 | |
| 15 | +def _handle_string_func(func): | |
| 16 | + def call_func(*args): | |
| 17 | + howlong = func('', 0, *args) | |
| 18 | + msg = 'x'*(howlong-1) | |
| 19 | + func(msg, howlong, *args) | |
| 20 | + return msg | |
| 21 | + return call_func | |
| 22 | + | |
| 15 | 23 | def init_brpy(br_loc='/usr/local/lib'): |
| 16 | 24 | """Takes the ctypes lib object for br and initializes all function inputs and outputs""" |
| 17 | 25 | br_loc += '/libopenbr.%s' |
| ... | ... | @@ -48,9 +56,14 @@ def init_brpy(br_loc='/usr/local/lib'): |
| 48 | 56 | br.br_is_classifier.restype = c_bool |
| 49 | 57 | br.br_make_mask.argtypes = _string_args(3) |
| 50 | 58 | br.br_make_pairwise_mask.argtypes = _string_args(3) |
| 51 | - br.br_most_recent_message.restype = c_char_p | |
| 52 | - br.br_objects.argtypes = _string_args(2) + [c_bool] | |
| 53 | - br.br_objects.restype = c_char_p | |
| 59 | + br.br_most_recent_message.argtypes = [c_char_p, c_int] | |
| 60 | + br.br_most_recent_message.restype = c_int | |
| 61 | + func = br.br_most_recent_message.__call__ | |
| 62 | + br.br_most_recent_message = _handle_string_func(func) | |
| 63 | + br.br_objects.argtypes = [c_char_p, c_int] + _string_args(2) + [c_bool] | |
| 64 | + br.br_objects.restype = c_int | |
| 65 | + func2 = br.br_objects.__call__ | |
| 66 | + br.br_objects = _handle_string_func(func2) | |
| 54 | 67 | br.br_plot.argtypes = plot_args |
| 55 | 68 | br.br_plot.restype = c_bool |
| 56 | 69 | br.br_plot_detection.argtypes = plot_args |
| ... | ... | @@ -61,7 +74,10 @@ def init_brpy(br_loc='/usr/local/lib'): |
| 61 | 74 | br.br_plot_metadata.restype = c_bool |
| 62 | 75 | br.br_progress.restype = c_float |
| 63 | 76 | br.br_read_pipe.argtypes = [c_char_p, POINTER(c_int), POINTER(POINTER(c_char_p))] |
| 64 | - br.br_scratch_path.restype = c_char_p | |
| 77 | + br.br_scratch_path.argtypes = [c_char_p, c_int] | |
| 78 | + br.br_scratch_path.restype = c_int | |
| 79 | + func3 = br.br_scratch_path.__call__ | |
| 80 | + br.br_scratch_path = _handle_string_func(func3) | |
| 65 | 81 | br.br_sdk_path.restype = c_char_p |
| 66 | 82 | br.br_get_header.argtypes = [c_char_p, POINTER(c_char_p), POINTER(c_char_p)] |
| 67 | 83 | br.br_set_header.argtypes = _string_args(3) |
| ... | ... | @@ -88,11 +104,15 @@ def init_brpy(br_loc='/usr/local/lib'): |
| 88 | 104 | br.br_img_channels.restype = c_int |
| 89 | 105 | br.br_img_is_empty.argtypes = [c_void_p] |
| 90 | 106 | br.br_img_is_empty.restype = c_bool |
| 91 | - br.br_get_filename.argtypes = [c_void_p] | |
| 92 | - br.br_get_filename.restype = c_char_p | |
| 107 | + br.br_get_filename.argtypes = [c_char_p, c_int, c_void_p] | |
| 108 | + br.br_get_filename.restype = c_int | |
| 109 | + func4 = br.br_get_filename.__call__ | |
| 110 | + br.br_get_filename = _handle_string_func(func4) | |
| 93 | 111 | br.br_set_filename.argtypes = [c_void_p, c_char_p] |
| 94 | - br.br_get_metadata_string.argtypes = [c_void_p, c_char_p] | |
| 95 | - br.br_get_metadata_string.restype = c_char_p | |
| 112 | + br.br_get_metadata_string.argtypes = [c_char_p, c_int, c_void_p, c_char_p] | |
| 113 | + br.br_get_metadata_string.restype = c_int | |
| 114 | + func5 = br.br_get_metadata_string.__call__ | |
| 115 | + br.br_get_metadata_string = _handle_string_func(func5) | |
| 96 | 116 | br.br_enroll_template.argtypes = [c_void_p] |
| 97 | 117 | br.br_enroll_template.restype = c_void_p |
| 98 | 118 | br.br_enroll_template_list.argtypes = [c_void_p] | ... | ... |