Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
qa_erode.cpp
1 
2 /***************************************************************************
3  * qa_erode.h - QA for erosion filter
4  *
5  * Generated: Mon May 21 21:31:57 2012
6  * Copyright 2012 Tim Niemueller [www.niemueller.de]
7  ****************************************************************************/
8 
9 /* This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version. A runtime exception applies to
13  * this software (see LICENSE.GPL_WRE file mentioned below for details).
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU Library General Public License for more details.
19  *
20  * Read the full text in the LICENSE.GPL_WRE file in the doc directory.
21  */
22 
23 /// @cond QA
24 
25 #include <fvutils/adapters/iplimage.h>
26 #include <fvutils/color/colorspaces.h>
27 #include <fvutils/readers/jpeg.h>
28 #include <fvutils/draw/drawer.h>
29 #include <fvfilters/morphology/erosion.h>
30 #include <fvwidgets/image_display.h>
31 #include <utils/system/argparser.h>
32 
33 #include <cstdlib>
34 #include <cstdio>
35 #include <cstring>
36 
37 using namespace fawkes;
38 using namespace firevision;
39 
40 int
41 main(int argc, char **argv)
42 {
43  ArgumentParser* argp = new ArgumentParser( argc, argv, "h:f:c:" );
44 
45  if (argp->has_arg( "f" ))
46  // read image from file
47  {
48  const char *image_file = argp->arg( "f" );
49 
50  JpegReader *reader = new JpegReader(image_file);
51  unsigned char *buffer = malloc_buffer(YUV422_PLANAR,
52  reader->pixel_width(), reader->pixel_height());
53 
54  reader->set_buffer(buffer);
55  reader->read();
56 
57  unsigned char *filtered = malloc_buffer(YUV422_PLANAR,
58  reader->pixel_width(), reader->pixel_height());
59  memset(filtered + reader->pixel_width() * reader->pixel_height(), 128,
60  reader->pixel_width() * reader->pixel_height());
61 
62  ROI *roi = ROI::full_image(reader->pixel_width(), reader->pixel_height());
63 
64 
65  FilterErosion *f = new FilterErosion();
66  f->set_src_buffer(buffer, roi);
67  f->set_dst_buffer(filtered, roi);
68  f->apply();
69 
70  ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height());
71  display->show(filtered);
72  display->loop_until_quit();
73 
74  delete display;
75 
76  delete roi;
77  free(buffer);
78  free(filtered);
79  delete f;
80  delete reader;
81  }
82 
83  else
84  {
85  printf("Usage: %s -f <Image file as JPEG>\n", argv[0]);
86  exit(-1);
87  }
88 
89  delete argp;
90 }
91 
92 /// @endcond