0

I m using this line with this function but I have an error.

filter2D(GaussKernel,conspic1,GaussKernel.depth(),split(GaussKernel,KernelAchrSplit),Point(-1,-1),0,BORDER_DEFAULT);

Kernel and conspic1 are Mat object. I suppose I have a problem with the kernel, because I don'tknow any function that returns me it. So I use split function

This is how to use the function for C++:

void filter2D(InputArray src, OutputArray dst, int ddepth, InputArray kernel, Point anchor=Point(-1,-1), double delta=0, int borderType=BORDER_DEFAULT );

The error I have is:

invalid use of void expression

Elvio
  • 17
  • 7

2 Answers2

0

You receive your error because cv::split() returns void, and cv::filter2D() expects a cv::Mat parameter as the fourth argument.

You can create an arbitrary kernel simply by creating a floating-point cv::Mat and filling the values with whatever you wish. One example:

cv::Mat kern = cv::Mat::ones(15,15, CV_32FC1)/225;

OpenCV also provides a few functions to calculate common kernels, such as cv::getGaussianKernel().

However, since it looks like you want to do Gaussian filtering, it is probably simpler to use cv::GaussianBlur().

Aurelius
  • 11,111
  • 3
  • 52
  • 69
0

What I have to do is translating from Matlab:

GaussKernel=fspecial('gaussian',maxhw,sigma);
conspic=filter2(GaussKernel,conspic,'same'); //Gaussian snoothing in each orientation

What I did is:

GaussianBlur(maxhw,GaussKernel,Size(0,0),1,1,BORDER_DEFAULT;
//setting 1,1 ; i m setting the Gaussian kernel standard deviation as 
//the paramether sigma in Matlab first line

filter2D(GaussKernel,conspic1,GaussKernel.depth(),split(GaussKernel,KernelAchrSplit),Point(-1,-1),0,BORDER_DEFAULT);
//I know I don t have to use split for the kernel paramether, but I suppose I have
// to use GaussKernel Mat object's kernel and I don t know how get it
Elvio
  • 17
  • 7
  • I would suggest you read the documentation I linked to. `cv::GaussianBlur` does not generate a Gaussian kernel, it does the blurring with parameters that you define. You appear to call the function correctly. Your second call to `cv::filter2D` is unnecessary. Also, this should be an edit to your question, not an answer. – Aurelius May 21 '13 at 15:12
  • _%Softening Gaussian filter_ _% Gaussian parameters as functions of image size_ . . . . . . . . . . . . . .... ,.... maxhw = max(0,floor(min(r/2,c/2) - 1)); . . . . . . . . . . . . . . .. . . . .. . . . .. . . . . . . . . .. . . . . .. . . . . . . . . . sigma = max(r,c)*0.025; . . . . . . .. . . . . . . .. . . . . . . .. . . . .. . . .. . . .. . . . .. . . .. . . . .. . . .. . . . . . . GaussKernel=fspecial('gaussian',maxhw,sigma); . . _% Gaussian smoothing in each orientation_ conspic=filter2(GaussKernel,conspic,'same'); conspic1 = conspic1 + conspic; – Elvio May 21 '13 at 18:01
  • this is what I need to do. Thanks for helping! Can you say me how to go down in the comments! I can posts what I did in C for this lines. Now I m not sure about sigma utilization in C – Elvio May 21 '13 at 18:01