www.pudn.com > GPUVision_5-13-05-2.zip > Canny.cpp
#include "Canny.h"
static float _gauss5xKernel[5] = {.125,.2,.5,.2,.125};
static float _gauss5x5Kernel[25] = {
.015625, .025000, .062500, .025000, .015625,
.025000, .040000, .010000, .040000, .025000,
.062500, .010000, .025000, .010000, .062500,
.025000, .040000, .010000, .040000, .025000,
.015625, .025000, .062500, .025000, .015625};
static float _gauss3xKernel[3] = {.25,.5,.25};
static float _gauss3x3Kernel[9] = {.0675, .125, .0675, .125, .5, .125, .0675, .125, .0675};
Canny::Canny(CGcontext context, float threshold, bool shouldBlur, bool shouldPack){
_shouldBlur = shouldBlur;
_shouldPack = shouldPack;
// should put this as a static class variable
_gauss5x5h = new ConvolutionFilter(_gauss5xKernel,5,1,3,context);
_gauss5x5v = new ConvolutionFilter(_gauss5xKernel,1,5,3,context);
_gauss5x5_2pack = new ConvolutionFilter2Pack(_gauss5x5Kernel,5,5,3,context);
_gauss3x3 = new ConvolutionFilter(_gauss3x3Kernel,3,3,3,context);
_rgb2grey = new RGB2GreyFilter();
_dxdy = new DxDyFilter();
_dxdy_2pack = new DxDy2PackFilter();
_nonMaxSupression = new NonMaxSupressionFilter(threshold);
_unpack2ChannelsFilter = new Unpack2ChannelsFilter();
_rgb2PackedUVFilter = new RGB2PackedUVFilter();
_pack2Filter = new Pack2Filter();
}
Canny::~Canny(){
delete _gauss5x5h;
delete _gauss5x5v;
delete _gauss5x5_2pack;
delete _gauss3x3;
delete _unpack2ChannelsFilter;
delete _rgb2PackedUVFilter;
delete _rgb2grey;
delete _dxdy;
delete _dxdy_2pack;
delete _nonMaxSupression;
delete _pack2Filter;
}
void Canny::cannyEdgeDetect(GPUVision *image1){
image1->Begin();
if(_shouldPack) {
this->_nonMaxSupression->setThreshold(this->_nonMaxSupression->getThreshold()-.08);
_rgb2PackedUVFilter->applyFilter(image1);
if(_shouldBlur) {
_gauss5x5_2pack->applyFilter(image1);
}
_unpack2ChannelsFilter->applyFilter(image1);
} else {
// greyscale the image
_rgb2grey->applyFilter(image1);
// _pack2Filter->applyFilter(image1);
// do a gaussian blur (sometimes this doesn't do much)
if(_shouldBlur) {
_gauss5x5v->applyFilter(image1);
_gauss5x5h->applyFilter(image1);
// _gauss3x3->applyFilter(image1);
}
// _unpack2ChannelsFilter->applyFilter(image1);
}
// calculate the x and y strengths
_dxdy->applyFilter(image1);
_nonMaxSupression->applyFilter(image1);
image1->End();
}