#include
#include
Mat mm = imread("girl.jpeg");
imshow("girl", mm); //显示函数
waitKey(0); //等待按下键
Mat element = getStructuringElement(MORPH_RECT, Size(10, 10)); //element为指定形状和尺寸的内核矩阵结构元素
Mat dstImage;
erode(mm, dstImage, element); //进行图像腐蚀操作
imshow("girl-腐蚀", dstImage);
waitKey(0);
结果:
Mat implicitpic;
blur(mm, implicitpic, Size(7, 7)); //模糊操作
imshow("均值滤波的模糊图", implicitpic);
waitKey(0);
结果:
#include
#include
using namespace cv;
int main()
{
//四、canny边缘检测
//要包含proc库文件,CV_BGR2GRAY
//#include
Mat edge, edge1,test;
Mat yuan = imread("girl.jpeg");
cvtColor(yuan, test, COLOR_BGR2GRAY); //转换为灰度值图像
imshow("灰度图1", test);
Mat grayImage = imread("girl.jpeg", IMREAD_GRAYSCALE); //直接以灰度图格式读入也可以
imshow("灰度图2", grayImage);
//flag=-2为默认
//flag=0为灰度图
//flag=66为三通道原彩
//flag=2|4为无损原图像
blur(test, edge, Size(3, 3)); //yonog用3*3的均值滤波来降噪
Canny(edge, edge1, 3, 9, 3);
imshow("边缘检测", edge1);
waitKey(0);
return 0;
}
结果:
ps:copyTo()
#include
#include
using namespace cv;
int main()
{
Mat image = imread("girl.jpeg"); //直接以灰度图格式读入也可以
imshow("原图", image);
Mat gray, edge, edge1, pict;
cvtColor(image, gray, COLOR_BGR2GRAY);
blur(gray, edge, Size(3, 3)); //yonog用3*3的均值滤波来降噪
Canny(edge, edge1, 3, 9, 3);
// 定义一个图属性
pict.create(image.size(), image.type());
pict = Scalar::all(0);
image.copyTo(pict, edge1);//edge1作为掩膜,把image通过掩膜复制到pict中
imshow("彩色边缘检测", pict);
waitKey(0);
return(0)
}
结果:
Mat girl = imread("girl.jpeg");
namedWindow("tu");
imshow("tu", girl);
waitKey();
Mat ff = imread("flower.jpeg");
namedWindow("hua2");
imshow("hua2", ff);
waitKey(0);
//dingyi定义一个mat类型,用于存放图像的roi
Mat imageROI2,imageROI;
imageROI = girl(Rect(100, 100, ff.cols, ff.rows)); //再原图中裁剪一部分,位置加大小,修改imageroi会直接修改原图
//Mat imageROI = image(Rect(350, 350+f.cows),Rect(800,800+f.cols));
//j讲花加到原图上
addWeighted(imageROI, 0.5, ff, 0.3, 0., imageROI); //两张图片不同的权重混合,并输出到
imshow("h", imageROI);
waitKey();
imshow("h混合", girl);
//b保存
imwrite("h混合图片.jpg", girl);
waitKey();