Fawkes API  Fawkes Development Version
qa_sobel.cpp
00001 
00002 /***************************************************************************
00003  *  qa_sobel.h - QA for Sobel filter
00004  *
00005  *  Generated: Mon May 21 17:42:25 2012
00006  *  Copyright  2012  Tim Niemueller [www.niemueller.de]
00007  ****************************************************************************/
00008 
00009 /*  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version. A runtime exception applies to
00013  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00021  */
00022 
00023 /// @cond QA
00024 
00025 #include <fvutils/adapters/iplimage.h>
00026 #include <fvutils/color/colorspaces.h>
00027 #include <fvutils/readers/jpeg.h>
00028 #include <fvutils/draw/drawer.h>
00029 #include <fvfilters/sobel.h>
00030 #include <fvwidgets/image_display.h>
00031 #include <utils/system/argparser.h>
00032 
00033 #include <cstdlib>
00034 #include <cstdio>
00035 #include <cstring>
00036 
00037 using namespace fawkes;
00038 using namespace firevision;
00039 
00040 int
00041 main(int argc, char **argv)
00042 {
00043   ArgumentParser* argp = new ArgumentParser( argc, argv, "h:f:c:" );
00044 
00045   if (argp->has_arg( "f" ))
00046     // read image from file
00047   {
00048     const char *image_file = argp->arg( "f" );
00049     
00050     JpegReader *reader = new JpegReader(image_file);
00051     unsigned char *buffer = malloc_buffer(YUV422_PLANAR,
00052                                           reader->pixel_width(), reader->pixel_height());
00053     
00054     reader->set_buffer(buffer);
00055     reader->read();
00056     
00057     unsigned char *sobeled = malloc_buffer(YUV422_PLANAR,
00058                                           reader->pixel_width(), reader->pixel_height());
00059     memset(sobeled + reader->pixel_width() * reader->pixel_height(), 128,
00060            reader->pixel_width() * reader->pixel_height());
00061 
00062     ROI *roi = ROI::full_image(reader->pixel_width(), reader->pixel_height());
00063 
00064 
00065     FilterSobel *sobelf = new FilterSobel();
00066     sobelf->set_src_buffer(buffer, roi, ORI_DEG_135);
00067     sobelf->set_dst_buffer(sobeled, roi);
00068     sobelf->apply();
00069     
00070     ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height());
00071     display->show(sobeled);
00072     display->loop_until_quit();
00073     
00074     delete display;
00075     
00076     delete roi;
00077     free(buffer);
00078     free(sobeled);
00079     delete sobelf;
00080     delete reader;
00081   }
00082 
00083   else
00084   {
00085     printf("Usage: %s -f <Image file as JPEG>\n", argv[0]);
00086     exit(-1);
00087   }
00088 
00089   delete argp;
00090 }
00091 
00092 /// @endcond