diff --git a/src/coco.c b/src/coco.c index ec49ae013d3..1ccb3bc8b63 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 e9017a0bd8c..7a258f3e70f 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 5ea7fc0077f..5171ee86a49 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 ca9f26651eb..3775837b2b4 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 90e6a04868b..65ccb7c7122 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 f13d460aca0..dfd497dfc80 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) {