I would like to know how I can do a low-pass filter in opencv on an IplImage. For example "boxcar" or something similar.
I've googled it but i can't find a clear solution. If anyone could give me an example or point me in the right direction on how to implement this in opencv or javacv I would be grateful.
Thx in advance.
Here is an example using the C API and IplImage:
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/highgui/highgui_c.h"
int main()
{
IplImage* img = cvLoadImage("input.jpg", 1);
IplImage* dst=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
cvSmooth(img, dst, CV_BLUR);
cvSaveImage("filtered.jpg",dst);
}
For information about what parameters of the cvSmooth function you can have a look at the cvSmooth Documentation.
If you want to use a custom filter mask you can use the function cvFilter2D
:
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/highgui/highgui_c.h"
int main()
{
IplImage* img = cvLoadImage("input.jpg", 1);
IplImage* dst=cvCreateImage(cvGetSize(img),IPL_DEPTH_8U,3);
double a[9]={ 1.0/9.0,1.0/9.0,1.0/9.0,
1.0/9.0,1.0/9.0,1.0/9.0,
1.0/9.0,1.0/9.0,1.0/9.0};
CvMat k;
cvInitMatHeader( &k, 3, 3, CV_64FC1, a );
cvFilter2D( img ,dst, &k,cvPoint(-1,-1));
cvSaveImage("filtered.jpg",dst);
}
These examples use OpenCV 2.3.1.
The openCV filtering documentation is a little confusing because the functions try and efficently cover every possible filtering technique.
There is a tutorial on using your own filter kernels which covers box filters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With