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