Fawkes API  Fawkes Development Version
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
hipass.cpp
1 
2 /***************************************************************************
3  * hipass.cpp - Implementation of a generic hipass filter
4  *
5  * Created: Thu Jun 16 17:12:16 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/hipass.h>
24 #include <core/exception.h>
25 
26 #ifdef HAVE_IPP
27 # include <ippi.h>
28 #elif defined(HAVE_OPENCV)
29 # include <cv.h>
30 #else
31 # error "Neither IPP nor OpenCV available"
32 #endif
33 
34 namespace firevision {
35 #if 0 /* just to make Emacs auto-indent happy */
36 }
37 #endif
38 
39 /** @class FilterHipass <fvfilters/hipass.h>
40  * Hipass filter.
41  */
42 
43 /** Constructor. */
44 FilterHipass::FilterHipass()
45  : Filter("FilterHipass")
46 {
47 }
48 
49 
50 void
52 {
53 #if defined(HAVE_IPP)
54  IppiSize size;
55  size.width = src_roi[0]->width;
56  size.height = src_roi[0]->height;
57 
58  IppStatus status;
59 
60  // base + number of bytes to line y + pixel bytes
61  status = ippiFilterHipass_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,
63  size, ippMskSize3x3 );
64 
65  if ( status != ippStsNoErr ) {
66  throw fawkes::Exception("Hipass filter failed with %i\n", status);
67  }
68 
69 #elif defined(HAVE_OPENCV)
70  cv::Mat srcm(src_roi[0]->height, src_roi[0]->width, CV_8UC1,
71  src[0] +
72  (src_roi[0]->start.y * src_roi[0]->line_step) +
73  (src_roi[0]->start.x * src_roi[0]->pixel_step),
74  src_roi[0]->line_step);
75 
76  if (dst == NULL) { dst = src[0]; dst_roi = src_roi[0]; }
77 
78  cv::Mat dstm(dst_roi->height, dst_roi->width, CV_8UC1,
79  dst +
83 
84  cv::Mat kernel(3, 3, CV_32F);
85  float *kernel_f = (float *)kernel.ptr();
86  kernel_f[0] = -1; kernel_f[1] = -1; kernel_f[2] = -1;
87  kernel_f[3] = -1; kernel_f[4] = 8; kernel_f[5] = -1;
88  kernel_f[6] = -1; kernel_f[7] = -1; kernel_f[8] = -1;
89 
90  cv::Point kanchor(1, 1);
91 
92  cv::filter2D(srcm, dstm, /* ddepth */ -1, kernel, kanchor);
93 #endif
94 }
95 
96 } // end namespace firevision
virtual void apply()
Apply the filter.
Definition: hipass.cpp:51
fawkes::point_t start
ROI start.
Definition: roi.h:118
unsigned int x
x coordinate
Definition: types.h:35
unsigned int width
ROI width.
Definition: roi.h:120
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
unsigned int y
y coordinate
Definition: types.h:36
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:70
unsigned int height
ROI height.
Definition: roi.h:122
unsigned int line_step
line step
Definition: roi.h:128
unsigned char * dst
Destination buffer.
Definition: filter.h:67
unsigned int pixel_step
pixel step
Definition: roi.h:130
ROI * dst_roi
Destination ROI.
Definition: filter.h:72