From 4098e4882c55076bfe6c02ce4ed469e86a414152 Mon Sep 17 00:00:00 2001 From: AlexeyAB Date: Wed, 20 May 2020 19:51:06 +0300 Subject: [PATCH] Minor fix --- src/image.c | 22 +++++++++++++++++++++- src/image.h | 1 + 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/image.c b/src/image.c index 099f6ebc..7b5d39f2 100644 --- a/src/image.c +++ b/src/image.c @@ -155,6 +155,25 @@ void draw_label(image a, int r, int c, image label, const float *rgb) } } +void draw_weighted_label(image a, int r, int c, image label, const float *rgb, const float alpha) +{ + int w = label.w; + int h = label.h; + if (r - h >= 0) r = r - h; + + int i, j, k; + for (j = 0; j < h && j + r < a.h; ++j) { + for (i = 0; i < w && i + c < a.w; ++i) { + for (k = 0; k < label.c; ++k) { + float val1 = get_pixel(label, i, j, k); + float val2 = get_pixel(a, i + c, j + r, k); + float val_dst = val1 * rgb[k] * alpha + val2 * (1 - alpha); + set_pixel(a, i + c, j + r, k, val_dst); + } + } + } +} + void draw_box_bw(image a, int x1, int y1, int x2, int y2, float brightness) { //normalize_image(a); @@ -423,7 +442,8 @@ void draw_detections_v3(image im, detection *dets, int num, float thresh, char * } } image label = get_label_v3(alphabet, labelstr, (im.h*.02)); - draw_label(im, top + width, left, label, rgb); + //draw_label(im, top + width, left, label, rgb); + draw_weighted_label(im, top + width, left, label, rgb, 0.7); free_image(label); } if (selected_detections[i].det.mask) { diff --git a/src/image.h b/src/image.h index 70d5f98d..90e6a048 100644 --- a/src/image.h +++ b/src/image.h @@ -28,6 +28,7 @@ void draw_box(image a, int x1, int y1, int x2, int y2, float r, float g, float b void draw_box_width(image a, int x1, int y1, int x2, int y2, int w, float r, float g, float b); void draw_bbox(image a, box bbox, int w, float r, float g, float b); void draw_label(image a, int r, int c, image label, const float *rgb); +void draw_weighted_label(image a, int r, int c, image label, const float *rgb, const float alpha); void write_label(image a, int r, int c, image *characters, char *string, float *rgb); void draw_detections(image im, int num, float thresh, box *boxes, float **probs, char **names, image **labels, int classes); void draw_detections_v3(image im, detection *dets, int num, float thresh, char **names, image **alphabet, int classes, int ext_output);