From ac4e765a4ae9ee3a150e75af1114191ff701a5e5 Mon Sep 17 00:00:00 2001 From: umbralada <30407896+umbralada@users.noreply.github.com> Date: Sat, 2 Sep 2023 00:15:01 +0300 Subject: [PATCH] added free_alphabet function; this function used for free alphabet. (#1805) --- src/coco.c | 3 +-- src/demo.c | 9 +-------- src/detector.c | 12 +----------- src/image.c | 13 +++++++++++++ src/image.h | 1 + src/yolo.c | 4 ++-- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/coco.c b/src/coco.c index ec49ae01..1ccb3bc8 100644 --- a/src/coco.c +++ b/src/coco.c @@ -374,10 +374,9 @@ void test_coco(char *cfgfile, char *weightfile, char *filename, float thresh) show_image(im, "predictions"); free_image(im); free_image(sized); - + free_alphabet(alphabet); wait_until_press_key_cv(); destroy_all_windows_cv(); - if (filename) break; } free(boxes); diff --git a/src/demo.c b/src/demo.c index e9017a0b..7a258f3e 100644 --- a/src/demo.c +++ b/src/demo.c @@ -413,14 +413,7 @@ void demo(char *cfgfile, char *weightfile, float thresh, float hier_thresh, int free_ptrs((void **)names, net.layers[net.n - 1].classes); - const int nsize = 8; - for (j = 0; j < nsize; ++j) { - for (i = 32; i < 127; ++i) { - free_image(alphabet[j][i]); - } - free(alphabet[j]); - } - free(alphabet); + free_alphabet(alphabet); free_network(net); //cudaProfilerStop(); } diff --git a/src/detector.c b/src/detector.c index 5ea7fc00..5171ee86 100644 --- a/src/detector.c +++ b/src/detector.c @@ -1778,17 +1778,7 @@ void test_detector(char *datacfg, char *cfgfile, char *weightfile, char *filenam free_ptrs((void**)names, net.layers[net.n - 1].classes); free_list_contents_kvp(options); free_list(options); - - int i; - const int nsize = 8; - for (j = 0; j < nsize; ++j) { - for (i = 32; i < 127; ++i) { - free_image(alphabet[j][i]); - } - free(alphabet[j]); - } - free(alphabet); - + free_alphabet(alphabet); free_network(net); } diff --git a/src/image.c b/src/image.c index ca9f2665..3775837b 100644 --- a/src/image.c +++ b/src/image.c @@ -280,6 +280,19 @@ image **load_alphabet() return alphabets; } +void free_alphabet(image **alphabet) +{ + int i, j; + const int nsize = 8; + for (j = 0; j < nsize; ++j) { + for (i = 32; i < 127; ++i) { + free_image(alphabet[j][i]); + } + free(alphabet[j]); + } + free(alphabet); +} + // Creates array of detections with prob > thresh and fills best_class for them diff --git a/src/image.h b/src/image.h index 90e6a048..65ccb7c7 100644 --- a/src/image.h +++ b/src/image.h @@ -88,6 +88,7 @@ image load_image(char *filename, int w, int h, int c); image load_image_stb_resize(char *filename, int w, int h, int c); //LIB_API image load_image_color(char *filename, int w, int h); image **load_alphabet(); +void free_alphabet(image **alphabet); //float get_pixel(image m, int x, int y, int c); //float get_pixel_extend(image m, int x, int y, int c); diff --git a/src/yolo.c b/src/yolo.c index f13d460a..dfd497df 100644 --- a/src/yolo.c +++ b/src/yolo.c @@ -328,11 +328,11 @@ void test_yolo(char *cfgfile, char *weightfile, char *filename, float thresh) free_image(im); free_image(sized); - + free_alphabet(alphabet); wait_until_press_key_cv(); destroy_all_windows_cv(); - if (filename) break; + if (filename) break; } free(boxes); for(j = 0; j < l.side*l.side*l.n; ++j) {