本文是在学习基于c++的opencv图像处理时所作的一些个人笔记,希望可以帮助一些忘记内容的读者回忆一些细节,有所启发。
#include
#include
#include
#include
#include<>iostream
using namespace cv;
using namespace std;
int main()
{
//线性滤波
//boxFilter()函数
Mat image1 = imread(“girl1.jpg”);
namedWindow(“原图”);
namedWindow(“boxfilter”);
imshow(“原图”, image1);
Mat out1;
boxFilter(image1, out1, -1, Size(5, 5));
imshow(“boxfilter”, out1);
//blur()函数
namedWindow(“blur”);
Mat out2;
blur(image1, out2, Size(7, 7));
imshow(“blur”, out2);
//GaussianBlur()函数
namedWindow(“GaussianBlur”);
Mat out3;
GaussianBlur(image1, out3,Size(3, 3),0,0);
imshow(“GaussianBlur”, out3);
//非线性滤波
//madianBlur()中值滤波函数
namedWindow("medianBlur");
Mat out4;
medianBlur(image1, out4, 7);
imshow("medianBlur", out4);
//bilateralFilter()双边滤波函数
namedWindow("bilateralFilter");
Mat out5;
bilateralFilter(image1,out5,25,25*2,25/2);
imshow("bilateralFilter", out5);
//形态学滤波
//dilate()膨胀函数
Mat element = getStructuringElement(MORPH_RECT, Size(15, 15));
Mat dst;
dilate(image1, dst, element);
namedWindow("dilate");
imshow("dilate", dst);
//erode()腐蚀函数
Mat element1 = getStructuringElement(MORPH_CROSS, Size(15, 15));
Mat dst1;
dilate(image1, dst1, element1);
namedWindow("erode");
imshow("erode", dst1);
//开闭运算
Mat dst2;
morphologyEx(image1, dst2, MORPH_OPEN, element);
namedWindow("open");
imshow("open", dst2);
Mat dst3;
morphologyEx(image1, dst3, MORPH_CLOSE, element);
namedWindow("close");
imshow("close", dst3);
//顶帽和黑帽运算
Mat dst4;
morphologyEx(image1, dst4, MORPH_TOPHAT, element);
namedWindow("tophat");
imshow("tophat", dst4);
Mat dst5;
morphologyEx(image1, dst5, MORPH_BLACKHAT, element);
namedWindow("blackhat");
imshow("blackhat", dst5);
//形态学梯度运算
Mat dst6;
morphologyEx(image1, dst6, MORPH_GRADIENT, element);
namedWindow("gradient");
imshow("gradient", dst6);
//漫水填充
Point seed = Point(50, 100);
Rect ccomp;
int flags = 4 + 38 << 8 +FLOODFILL_FIXED_RANGE;
Mat mask = imread("image", 0);
int area = floodFill(image1, mask,seed, Scalar(55, 155, 100), &ccomp, Scalar(20, 20, 20), Scalar(20, 20, 20), flags);
//resize()尺寸缩放函数
//调用一
Mat dstImage = Mat::zeros(512, 512, CV_8UC3);
resize(image1, dstImage, dstImage.size());
//调用二
Mat dstImage2;
resize(image1, dstImage2, Size(), 0.5, 0.5);
//resize(image1,dstImage,Size(image1.cols/2,image1.rows/2),(0,0),(0,0),3);
//pyrUp向上采样函数
Mat dstImage3;
pyrUp(image1, dstImage3, Size(image1.cols * 2, image1.rows * 2));
//pyrDown向上采样函数
Mat dstImage4;
pyrUp(image1, dstImage4, Size(image1.cols /2, image1.rows /2));
//threshold()固定阈值操作函数
Mat dstImage5;
double thresh=0;
threshold(image1, dstImage5, thresh, 255, 0);
//adaptiveThreshold()自适应阈值操作函数
Mat dstImage6;
double maxValue;
adaptiveThreshold(image1, dstImage6, maxValue, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 5, 10);
waitKey(0);
//system("pause");
//return 0;
}