24 #include <fvutils/colormap/cmfile.h> 25 #include <fvutils/colormap/colormap.h> 26 #include <fvutils/colormap/yuvcm.h> 27 #include <utils/system/argparser.h> 34 using namespace firevision;
37 main(
int argc,
char **argv)
42 char *out_file = NULL;
45 in_file = strdup(argp->
arg(
"i"));
49 out_file = strdup(argp->
arg(
"o"));
52 if (!in_file || !out_file) {
53 printf(
"Usage: argv[0] -i <input colormap> -o <output colormap>\n");
55 printf(
"Reading colormap from file %s.\n", in_file);
56 printf(
"Writing modified colormap to file %s.\n", out_file);
61 unsigned int cm_width = cm->
width();
62 unsigned int cm_height = cm->
height();
63 unsigned int cm_depth = cm->
depth();
65 unsigned char *cm_buffer = (
unsigned char *)malloc(cm->
size());
71 for (
unsigned int d = 0; d < cm_depth; ++d) {
72 for (
unsigned int w = 0; w < cm_width; ++w) {
73 for (
unsigned int h = 0; h < cm_height; ++h) {
75 unsigned int y = (
unsigned int)(d * yuvfac);
77 color_t cur_color = cm->
determine(y, w, h);
80 if (cur_color != C_OTHER) {
84 unsigned int cm_counter[C_OTHER + 1];
86 for (
unsigned int i = 0; i <= C_OTHER; ++i) {
90 unsigned int tst_radius_dp = 1;
91 unsigned int tst_radius_uv = 4;
93 unsigned int num_neighbours = 0;
95 for (
unsigned int dd = (
unsigned int)fmax(d - tst_radius_dp, 0);
96 dd <= fmin(d + tst_radius_dp, cm_depth - 1);
98 for (
unsigned int ww = (
unsigned int)fmax(w - tst_radius_uv, 0);
99 ww <= fmin(w + tst_radius_uv, cm_width - 1);
101 for (
unsigned int hh = (
unsigned int)fmax(h - tst_radius_uv, 0);
102 hh <= fmin(h + tst_radius_uv, cm_height - 1);
104 color_t cur_color = cm->
determine((
unsigned int)(dd * yuvfac), ww, hh);
105 ++cm_counter[cur_color];
112 unsigned int max = 0;
113 color_t max_color = C_OTHER;
115 for (
unsigned int i = 0; i < C_OTHER; ++i) {
116 if (cm_counter[i] > max) {
118 max_color = (color_t)i;
122 if (max > num_neighbours * 0.1 && max_color != C_OTHER) {
123 printf(
"max=%u max_color=%d num_neighbours=%u\n", max, max_color, num_neighbours);
124 cmpp->set(y, w, h, max_color);
131 cmout.add_colormap(cmpp);
132 printf(
"Writing modified colormap.\n");
133 cmout.write(out_file);
const char * arg(const char *argn)
Get argument value.
virtual unsigned int depth() const =0
Get depth of colormap.
Fawkes library namespace.
Parse command line arguments.
virtual unsigned int height() const =0
Get height of colormap.
Colormap * get_colormap()
Get a freshly generated colormap based on current file content.
virtual void read(const char *file_name)
Read file.
virtual color_t determine(unsigned int y, unsigned int u, unsigned int v) const =0
Determine color class for given YUV value.
virtual size_t size()=0
Size in bytes of buffer returned by get_buffer().
virtual unsigned int width() const =0
Get width of colormap.
virtual unsigned int deepness() const =0
Get deepness of colormap.
virtual unsigned char * get_buffer() const =0
Get the raw buffer of this colormap.
bool has_arg(const char *argn)
Check if argument has been supplied.