基于c++的opencv图像处理学习笔记二

本文是在学习基于c++的opencv图像处理时所作的一些个人笔记,希望可以帮助一些忘记内容的读者回忆一些细节,有所启发。
#include<opencv2/opencv.hpp>
#include<opencv2/core/core.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<imgproc/imgproc.hpp>
#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;

}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值