Skip to content

Commit 48268b6

Browse files
committed
janus: vision part
1 parent 9d8ffa5 commit 48268b6

File tree

2 files changed

+21
-20
lines changed

2 files changed

+21
-20
lines changed

src/vision_process.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ namespace vision
338338
}
339339
}
340340

341-
void image_load(const char *fn, std::vector<uint8_t> &rgb_pixels, int &width, int &height, int patch_size, PaddingMode pad)
341+
void image_load(const char *fn, std::vector<uint8_t> &rgb_pixels, int &width, int &height, int patch_size, const std::string &pad)
342342
{
343343
// magick -depth 8 demo.jpeg -resize 100x100 rgb:"aaa.raw"
344344
rgb_pixels.clear();
@@ -401,30 +401,30 @@ namespace vision
401401
}
402402
}
403403

404-
oss << " -resize " << width << "x" << height << "!";
404+
oss << " -resize \"" << width << "x" << height << "\\>\"";
405405

406406
int aligned_width = 0;
407407
int aligned_height = 0;
408408
const int patch_size_w = params.merge_kernel_size[0] > 0 ? patch_size * params.merge_kernel_size[0] : patch_size;
409409
const int patch_size_h = params.merge_kernel_size[1] > 0 ? patch_size * params.merge_kernel_size[1] : patch_size;
410410

411-
if (pad != PaddingMode::No)
411+
if (params.do_resize)
412+
{
413+
aligned_width = width;
414+
aligned_height = height;
415+
416+
oss << " -compose Copy -gravity northwest";
417+
oss << " -background " << (pad != PaddingMode::No ? pad : "white");
418+
oss << " -extent " << aligned_width << "x" << aligned_height;
419+
}
420+
else if (pad != PaddingMode::No)
412421
{
413422
aligned_width = ((width + patch_size_w - 1) / patch_size_w) * patch_size_w;
414423
aligned_height = ((height + patch_size_h - 1) / patch_size_h) * patch_size_h;
415424

416-
oss << " -background ";
417-
switch (pad)
418-
{
419-
case PaddingMode::Black:
420-
oss << "black";
421-
break;
422-
423-
default:
424-
oss << "white";
425-
break;
426-
}
427-
oss << " -compose Copy -gravity northwest -extent " << aligned_width << "x" << aligned_height;
425+
oss << " -compose Copy -gravity northwest";
426+
oss << " -background " << pad;
427+
oss << " -extent " << aligned_width << "x" << aligned_height;
428428
}
429429
else
430430
{

src/vision_process.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
namespace vision
88
{
9-
enum PaddingMode
9+
namespace PaddingMode
1010
{
11-
No,
12-
Black,
13-
White,
11+
const std::string No = "no";
12+
const std::string Black = "black";
13+
const std::string White = "white";
14+
const std::string Gray = "#7f7f7f";
1415
};
1516

1617
enum PatchesFormat
@@ -111,7 +112,7 @@ namespace vision
111112
typedef std::vector<uint8_t> image_pixels_t; // natural sequence of RGB pixels
112113

113114
void image_dimension(const char *fn, int &width, int &height);
114-
void image_load(const char *fn, std::vector<uint8_t> &rgb_pixels, int &width, int &height, int patch_size, PaddingMode pad = PaddingMode::No);
115+
void image_load(const char *fn, std::vector<uint8_t> &rgb_pixels, int &width, int &height, int patch_size, const std::string &pad = PaddingMode::No);
115116
void image_load_split(const char *fn, std::vector<image_pixels_t> &splits, bool do_split, const int split_width, const int split_height, int &splits_cols_num, int &splits_rows_num); // splits are in natural order
116117
void image_load_pan_and_scan(const char *fn, std::vector<image_pixels_t> &crops, bool do_pas,
117118
const int min_crop_size, const int max_num_crops, float min_ratio_to_activate,

0 commit comments

Comments
 (0)