Fawkes API  Fawkes Development Version
sharpen.cpp
1 
2 /***************************************************************************
3  * sharpen.cpp - Implementation of the sharpen filter
4  *
5  * Created: Thu Jun 16 16:13:15 2005
6  * Copyright 2005-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 #include <core/exception.h>
24 #include <fvfilters/sharpen.h>
25 
26 #ifdef HAVE_IPP
27 # include <ippi.h>
28 #elif defined(HAVE_OPENCV)
29 # if CV_MAJOR_VERSION < 2 || (CV_MAJOR_VERSION == 2 && CV_MINOR_VERSION < 4)
30 # include <opencv/cv.h>
31 # endif
32 # include <opencv/cv.hpp>
33 #else
34 # error "Neither IPP nor OpenCV available"
35 #endif
36 
37 namespace firevision {
38 
39 /** @class FilterSharpen <fvfilters/sharpen.h>
40  * Sharpen filter.
41  * @author Tim Niemueller
42  */
43 
44 /** Constructor. */
46 {
47 }
48 
49 void
51 {
52 #if defined(HAVE_IPP)
53  IppiSize size;
54  size.width = src_roi[0]->width;
55  size.height = src_roi[0]->height;
56 
57  IppStatus status;
58 
59  // base + number of bytes to line y + pixel bytes
60  status = ippiFilterSharpen_8u_C1R(src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
61  + (src_roi[0]->start.x * src_roi[0]->pixel_step),
62  src_roi[0]->line_step,
66  size);
67 
68  if (status != ippStsNoErr) {
69  throw fawkes::Exception("Sharpen filter failed with %i\n", status);
70  }
71 #elif defined(HAVE_OPENCV)
72  if ((dst == NULL) || (dst == src[0])) {
73  throw fawkes::Exception("OpenCV-based Sobel filter cannot be in-place");
74  }
75 
76  cv::Mat srcm(src_roi[0]->height,
77  src_roi[0]->width,
78  CV_8UC1,
79  src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
80  + (src_roi[0]->start.x * src_roi[0]->pixel_step),
81  src_roi[0]->line_step);
82 
83  cv::Mat dstm(dst_roi->height,
84  dst_roi->width,
85  CV_8UC1,
89 
90  cv::Mat kernel(3, 3, CV_32F);
91  float * kernel_f = (float *)kernel.ptr();
92  kernel_f[0] = -0.125;
93  kernel_f[1] = -0.125;
94  kernel_f[2] = -0.125;
95  kernel_f[3] = -0.125;
96  kernel_f[4] = 2.0;
97  kernel_f[5] = -0.125;
98  kernel_f[6] = -0.125;
99  kernel_f[7] = -0.125;
100  kernel_f[8] = -0.125;
101 
102  cv::Point kanchor(1, 1);
103 
104  cv::filter2D(srcm, dstm, /* ddepth */ -1, kernel, kanchor);
105 
106 #endif
107 }
108 
109 } // end namespace firevision
firevision::ROI::width
unsigned int width
ROI width.
Definition: roi.h:117
firevision::Filter::src
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:61
firevision::ROI::height
unsigned int height
ROI height.
Definition: roi.h:119
firevision::FilterSharpen::FilterSharpen
FilterSharpen()
Constructor.
Definition: sharpen.cpp:45
firevision::Filter::src_roi
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:66
fawkes::upoint_t::y
unsigned int y
y coordinate
Definition: types.h:37
firevision::ROI::pixel_step
unsigned int pixel_step
pixel step
Definition: roi.h:127
firevision::Filter::dst_roi
ROI * dst_roi
Destination ROI.
Definition: filter.h:68
firevision::FilterSharpen::apply
virtual void apply()
Apply the filter.
Definition: sharpen.cpp:50
firevision::ROI::start
fawkes::upoint_t start
ROI start.
Definition: roi.h:115
firevision::ROI::line_step
unsigned int line_step
line step
Definition: roi.h:125
fawkes::upoint_t::x
unsigned int x
x coordinate
Definition: types.h:36
firevision::Filter
Filter interface.
Definition: filter.h:33
firevision::Filter::dst
unsigned char * dst
Destination buffer.
Definition: filter.h:63
fawkes::Exception
Base class for exceptions in Fawkes.
Definition: exception.h:36