Fawkes API
Fawkes Development Version
|
00001 00002 /*************************************************************************** 00003 * sharpen.cpp - Implementation of the sharpen filter 00004 * 00005 * Created: Thu Jun 16 16:13:15 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/sharpen.h> 00024 00025 #include <core/exception.h> 00026 00027 #ifdef HAVE_IPP 00028 # include <ippi.h> 00029 #elif defined(HAVE_OPENCV) 00030 # include <cv.h> 00031 #else 00032 # error "Neither IPP nor OpenCV available" 00033 #endif 00034 00035 namespace firevision { 00036 #if 0 /* just to make Emacs auto-indent happy */ 00037 } 00038 #endif 00039 00040 /** @class FilterSharpen <fvfilters/sharpen.h> 00041 * Sharpen filter. 00042 * @author Tim Niemueller 00043 */ 00044 00045 /** Constructor. */ 00046 FilterSharpen::FilterSharpen() 00047 : Filter("FilterSharpen") 00048 { 00049 } 00050 00051 00052 void 00053 FilterSharpen::apply() 00054 { 00055 #if defined(HAVE_IPP) 00056 IppiSize size; 00057 size.width = src_roi[0]->width; 00058 size.height = src_roi[0]->height; 00059 00060 IppStatus status; 00061 00062 // base + number of bytes to line y + pixel bytes 00063 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, 00064 dst + (dst_roi->start.y * dst_roi->line_step) + (dst_roi->start.x * dst_roi->pixel_step), dst_roi->line_step, 00065 size ); 00066 00067 if ( status != ippStsNoErr ) { 00068 throw fawkes::Exception("Sharpen filter failed with %i\n", status); 00069 } 00070 #elif defined(HAVE_OPENCV) 00071 if ((dst == NULL) || (dst == src[0])) { 00072 throw fawkes::Exception("OpenCV-based Sobel filter cannot be in-place"); 00073 } 00074 00075 cv::Mat srcm(src_roi[0]->height, src_roi[0]->width, CV_8UC1, 00076 src[0] + 00077 (src_roi[0]->start.y * src_roi[0]->line_step) + 00078 (src_roi[0]->start.x * src_roi[0]->pixel_step), 00079 src_roi[0]->line_step); 00080 00081 cv::Mat dstm(dst_roi->height, dst_roi->width, CV_8UC1, 00082 dst + 00083 (dst_roi->start.y * dst_roi->line_step) + 00084 (dst_roi->start.x * dst_roi->pixel_step), 00085 dst_roi->line_step); 00086 00087 cv::Mat kernel(3, 3, CV_32F); 00088 float *kernel_f = (float *)kernel.ptr(); 00089 kernel_f[0] = -0.125; kernel_f[1] = -0.125; kernel_f[2] = -0.125; 00090 kernel_f[3] = -0.125; kernel_f[4] = 2.0; kernel_f[5] = -0.125; 00091 kernel_f[6] = -0.125; kernel_f[7] = -0.125; kernel_f[8] = -0.125; 00092 00093 cv::Point kanchor(1, 1); 00094 00095 cv::filter2D(srcm, dstm, /* ddepth */ -1, kernel, kanchor); 00096 00097 #endif 00098 00099 } 00100 00101 } // end namespace firevision