Fawkes API  Fawkes Development Version
hipass.cpp
00001 
00002 /***************************************************************************
00003  *  hipass.cpp - Implementation of a generic hipass filter
00004  *
00005  *  Created: Thu Jun 16 17:12:16 2005
00006  *  Copyright  2005-2012  Tim Niemueller [www.niemueller.de]
00007  ****************************************************************************/
00008 
00009 /*  This program is free software; you can redistribute it and/or modify
00010  *  it under the terms of the GNU General Public License as published by
00011  *  the Free Software Foundation; either version 2 of the License, or
00012  *  (at your option) any later version. A runtime exception applies to
00013  *  this software (see LICENSE.GPL_WRE file mentioned below for details).
00014  *
00015  *  This program is distributed in the hope that it will be useful,
00016  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00017  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018  *  GNU Library General Public License for more details.
00019  *
00020  *  Read the full text in the LICENSE.GPL_WRE file in the doc directory.
00021  */
00022 
00023 #include <fvfilters/hipass.h>
00024 #include <core/exception.h>
00025 
00026 #ifdef HAVE_IPP
00027 #  include <ippi.h>
00028 #elif defined(HAVE_OPENCV)
00029 #  include <cv.h>
00030 #else
00031 #  error "Neither IPP nor OpenCV available"
00032 #endif
00033 
00034 namespace firevision {
00035 #if 0 /* just to make Emacs auto-indent happy */
00036 }
00037 #endif
00038 
00039 /** @class FilterHipass <fvfilters/hipass.h>
00040  * Hipass filter.
00041  */
00042 
00043 /** Constructor. */
00044 FilterHipass::FilterHipass()
00045   : Filter("FilterHipass")
00046 {
00047 }
00048 
00049 
00050 void
00051 FilterHipass::apply()
00052 {
00053 #if defined(HAVE_IPP)
00054   IppiSize size;
00055   size.width = src_roi[0]->width;
00056   size.height = src_roi[0]->height;
00057 
00058   IppStatus status;
00059 
00060   //                                    base + number of bytes to line y              + pixel bytes
00061   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,
00062                                     dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step), dst_roi->line_step,
00063                                     size, ippMskSize3x3 );
00064 
00065   if ( status != ippStsNoErr ) {
00066     throw fawkes::Exception("Hipass filter failed with %i\n", status);
00067   }
00068 
00069 #elif defined(HAVE_OPENCV)
00070   cv::Mat srcm(src_roi[0]->height, src_roi[0]->width, CV_8UC1,
00071                src[0] +
00072                  (src_roi[0]->start.y * src_roi[0]->line_step) +
00073                  (src_roi[0]->start.x * src_roi[0]->pixel_step),
00074                src_roi[0]->line_step);
00075 
00076   if (dst == NULL) { dst = src[0]; dst_roi = src_roi[0]; }
00077 
00078   cv::Mat dstm(dst_roi->height, dst_roi->width, CV_8UC1,
00079                dst +
00080                  (dst_roi->start.y * dst_roi->line_step) +
00081                  (dst_roi->start.x * dst_roi->pixel_step),
00082                dst_roi->line_step);
00083 
00084   cv::Mat kernel(3, 3, CV_32F);
00085   float *kernel_f = (float *)kernel.ptr();
00086   kernel_f[0] = -1; kernel_f[1] = -1; kernel_f[2] = -1;
00087   kernel_f[3] = -1; kernel_f[4] =  8; kernel_f[5] = -1;
00088   kernel_f[6] = -1; kernel_f[7] = -1; kernel_f[8] = -1;
00089 
00090   cv::Point kanchor(1, 1);
00091 
00092   cv::filter2D(srcm, dstm, /* ddepth */ -1, kernel, kanchor);
00093 #endif
00094 }
00095 
00096 } // end namespace firevision