Fawkes API  Fawkes Development Version
gauss.cpp
1 
2 /***************************************************************************
3  * gauss.cpp - Implementation of a Gauss filter
4  *
5  * Created: Thu May 12 09:33:55 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/gauss.h>
24 
25 #include <cstddef>
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 
40 /** @class FilterGauss <fvfilters/gauss.h>
41  * Gaussian filter.
42  * Applies Gaussian linear filter to image (blur effect).
43  */
44 
45 /** Constructor. */
46 FilterGauss::FilterGauss() : Filter("FilterGauss")
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 = */ ippiFilterGauss_8u_C1R(
59  src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
60  + (src_roi[0]->start.x * src_roi[0]->pixel_step),
61  src_roi[0]->line_step,
64  size,
65  ippMskSize5x5);
66 
67  /*
68  cout << "FilterGauss: ippiFilterGauss exit code: " << flush;
69  switch (status) {
70  case ippStsNoErr:
71  cout << "ippStsNoErr";
72  break;
73  case ippStsNullPtrErr:
74  cout << "ippStsNullPtrErr";
75  break;
76  case ippStsSizeErr:
77  cout << "ippStsSizeErr";
78  break;
79  case ippStsStepErr:
80  cout << "ippStsStepErr";
81  break;
82  case ippStsMaskSizeErr:
83  cout << "ippStsMaskSizeErr";
84  break;
85  default:
86  cout << "Unknown status";
87  }
88  cout << endl;
89  */
90 
91 #elif defined(HAVE_OPENCV)
92  cv::Mat srcm(src_roi[0]->height,
93  src_roi[0]->width,
94  CV_8UC1,
95  src[0] + (src_roi[0]->start.y * src_roi[0]->line_step)
96  + (src_roi[0]->start.x * src_roi[0]->pixel_step),
97  src_roi[0]->line_step);
98 
99  if (dst == NULL) {
100  dst = src[0];
101  dst_roi = src_roi[0];
102  }
103 
104  cv::Mat dstm(dst_roi->height,
105  dst_roi->width,
106  CV_8UC1,
108  + (dst_roi->start.x * dst_roi->pixel_step),
109  dst_roi->line_step);
110 
111  cv::GaussianBlur(srcm, dstm, /* ksize */ cv::Size(5, 5), /* sigma */ 1.0);
112 
113 #endif
114 }
115 
116 } // end namespace firevision
virtual void apply()
Apply the filter.
Definition: gauss.cpp:51
FilterGauss()
Constructor.
Definition: gauss.cpp:46
Filter interface.
Definition: filter.h:33
ROI ** src_roi
Source ROIs, dynamically allocated by Filter ctor.
Definition: filter.h:66
unsigned char ** src
Source buffers, dynamically allocated by Filter ctor.
Definition: filter.h:61
unsigned char * dst
Destination buffer.
Definition: filter.h:63
ROI * dst_roi
Destination ROI.
Definition: filter.h:68
unsigned int height
ROI height.
Definition: roi.h:119
fawkes::upoint_t start
ROI start.
Definition: roi.h:115
unsigned int line_step
line step
Definition: roi.h:125
unsigned int width
ROI width.
Definition: roi.h:117
unsigned int pixel_step
pixel step
Definition: roi.h:127
unsigned int x
x coordinate
Definition: types.h:36
unsigned int y
y coordinate
Definition: types.h:37