|
|
|
@ -883,6 +883,51 @@ void composite_3d(char *f1, char *f2, char *out, int delta) |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void fill_image(image m, float s) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
for (i = 0; i < m.h*m.w*m.c; ++i) m.data[i] = s; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void letterbox_image_into(image im, int w, int h, image boxed) |
|
|
|
|
{ |
|
|
|
|
int new_w = im.w; |
|
|
|
|
int new_h = im.h; |
|
|
|
|
if (((float)w / im.w) < ((float)h / im.h)) { |
|
|
|
|
new_w = w; |
|
|
|
|
new_h = (im.h * w) / im.w; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
new_h = h; |
|
|
|
|
new_w = (im.w * h) / im.h; |
|
|
|
|
} |
|
|
|
|
image resized = resize_image(im, new_w, new_h); |
|
|
|
|
embed_image(resized, boxed, (w - new_w) / 2, (h - new_h) / 2); |
|
|
|
|
free_image(resized); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
image letterbox_image(image im, int w, int h) |
|
|
|
|
{ |
|
|
|
|
int new_w = im.w; |
|
|
|
|
int new_h = im.h; |
|
|
|
|
if (((float)w / im.w) < ((float)h / im.h)) { |
|
|
|
|
new_w = w; |
|
|
|
|
new_h = (im.h * w) / im.w; |
|
|
|
|
} |
|
|
|
|
else { |
|
|
|
|
new_h = h; |
|
|
|
|
new_w = (im.w * h) / im.h; |
|
|
|
|
} |
|
|
|
|
image resized = resize_image(im, new_w, new_h); |
|
|
|
|
image boxed = make_image(w, h, im.c); |
|
|
|
|
fill_image(boxed, .5); |
|
|
|
|
//int i;
|
|
|
|
|
//for(i = 0; i < boxed.w*boxed.h*boxed.c; ++i) boxed.data[i] = 0;
|
|
|
|
|
embed_image(resized, boxed, (w - new_w) / 2, (h - new_h) / 2); |
|
|
|
|
free_image(resized); |
|
|
|
|
return boxed; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
image resize_max(image im, int max) |
|
|
|
|
{ |
|
|
|
|
int w = im.w; |
|
|
|
@ -1312,6 +1357,7 @@ image load_image(char *filename, int w, int h, int c) |
|
|
|
|
|
|
|
|
|
#ifndef CV_VERSION_EPOCH |
|
|
|
|
image out = load_image_stb(filename, c); // OpenCV 3.x
|
|
|
|
|
//image out = load_image_cv(filename, c);
|
|
|
|
|
#else |
|
|
|
|
image out = load_image_cv(filename, c); // OpenCV 2.4.x
|
|
|
|
|
#endif |
|
|
|
|