Filtering image: dilation, inversion, erosion

#include "stdafx.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/photo/photo.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui.hpp"
//#include "opencv2/contrib/contrib.hpp"
#include "opencv2/core/core_c.h"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/core/core.hpp"

using namespace cv;
#include <iostream>

using namespace std;

int main()
{
//display the original image
IplImage* img = cvLoadImage("Deepika_Padukone.jpg");
cvNamedWindow("MyWindow");
cvShowImage("MyWindow", img);
while (1)
{

IplImage* img2 = img;
int ans = waitKey(30);
if (ans == 65)
{
//erode and display the eroded image
cvErode(img, img2, 0, 2);
cvNamedWindow("Eroded");
cvShowImage("Eroded", img2);
}
else if (ans == 66)
{
//dilate and display the eroded image
cvDilate(img, img2, 0, 2);
cvNamedWindow("dilated");
cvShowImage("dilated", img2);
}
else if (ans == 67)
{
//invert and display the eroded image
cvNot(img, img2);
cvNamedWindow("inverted");
cvShowImage("inverted", img2);
}

}
cvWaitKey(0);

//cleaning up
cvDestroyWindow("MyWindow");
cvDestroyWindow("Eroded");
cvReleaseImage(&img);

return 0;
}

Press A, B, C and see the magic 😉

Leave a Reply

Your email address will not be published. Required fields are marked *