Fawkes API Fawkes Development Version
qa_sobel.cpp
1
2/***************************************************************************
3 * qa_sobel.h - QA for Sobel filter
4 *
5 * Generated: Mon May 21 17:42:25 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 <fvfilters/sobel.h>
26#include <fvutils/adapters/cvmatadapter.h>
27#include <fvutils/color/colorspaces.h>
28#include <fvutils/draw/drawer.h>
29#include <fvutils/readers/jpeg.h>
30#include <fvwidgets/image_display.h>
31#include <utils/system/argparser.h>
32
33#include <cstdio>
34#include <cstdlib>
35#include <cstring>
36
37using namespace fawkes;
38using namespace firevision;
39
40int
41main(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 =
52 malloc_buffer(YUV422_PLANAR, reader->pixel_width(), reader->pixel_height());
53
54 reader->set_buffer(buffer);
55 reader->read();
56
57 unsigned char *sobeled =
58 malloc_buffer(YUV422_PLANAR, reader->pixel_width(), reader->pixel_height());
59 memset(sobeled + reader->pixel_width() * reader->pixel_height(),
60 128,
61 reader->pixel_width() * reader->pixel_height());
62
63 ROI *roi = ROI::full_image(reader->pixel_width(), reader->pixel_height());
64
65 FilterSobel *sobelf = new FilterSobel();
66 sobelf->set_src_buffer(buffer, roi, ORI_DEG_135);
67 sobelf->set_dst_buffer(sobeled, roi);
68 sobelf->apply();
69
70 ImageDisplay *display = new ImageDisplay(reader->pixel_width(), reader->pixel_height());
71 display->show(sobeled);
72 display->loop_until_quit();
73
74 delete display;
75
76 delete roi;
77 free(buffer);
78 free(sobeled);
79 delete sobelf;
80 delete reader;
81 }
82
83 else {
84 printf("Usage: %s -f <Image file as JPEG>\n", argv[0]);
85 exit(-1);
86 }
87
88 delete argp;
89}
90
91/// @endcond
Parse command line arguments.
Definition: argparser.h:64
const char * arg(const char *argn)
Get argument value.
Definition: argparser.cpp:177
bool has_arg(const char *argn)
Check if argument has been supplied.
Definition: argparser.cpp:165
Sobel filter.
Definition: sobel.h:35
virtual void apply()
Apply the filter.
Definition: sobel.cpp:158
virtual void set_dst_buffer(unsigned char *buf, ROI *roi)
Set the destination buffer.
Definition: filter.cpp:123
virtual void set_src_buffer(unsigned char *buf, ROI *roi, orientation_t ori=ORI_HORIZONTAL, unsigned int buffer_num=0)
Set source buffer with orientation.
Definition: filter.cpp:89
Simple image display.
Definition: image_display.h:36
JPEG file reader.
Definition: jpeg.h:37
virtual unsigned int pixel_width()
Get width of read image in pixels.
Definition: jpeg.cpp:89
virtual unsigned int pixel_height()
Get height of read image in pixels.
Definition: jpeg.cpp:99
virtual void read()
Read data from file.
Definition: jpeg.cpp:109
virtual void set_buffer(unsigned char *yuv422planar_buffer)
Set buffer that the read image should be written to.
Definition: jpeg.cpp:77
Region of interest.
Definition: roi.h:55
Fawkes library namespace.