#include<opencv2/opencv.hpp>usingnamespace cv;intmain(){
Mat src =imread("D:\\desk\\demo.jpg");imshow("原图",src);waitKey(0);return0;}
2.图像腐蚀
#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgproc/imgproc.hpp>usingnamespace cv;intmain(){
Mat src =imread("D:\\desk\\demo.jpg");imshow("原图",src);
Mat element =getStructuringElement(MORPH_RECT,Size(15,15));
Mat dstImg;erode(src, dstImg, element);imshow("腐蚀后", dstImg);waitKey(0);return0;}
3.图片模糊
#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgproc/imgproc.hpp>#include<opencv2/opencv.hpp>usingnamespace cv;intmain(){
Mat src =imread("D:\\desk\\demo.jpg");imshow("原图",src);
Mat dstImg;blur(src, dstImg,Size(8,10));imshow("均值滤波后", dstImg);waitKey(0);return0;}
4.边缘检测
#include<opencv2/highgui/highgui.hpp>#include<opencv2/imgproc/imgproc.hpp>#include<opencv2/opencv.hpp>usingnamespace cv;intmain(){
Mat src =imread("D:\\desk\\demo.jpg");imshow("原图",src);
Mat edge,grayImg;cvtColor(src, grayImg, COLOR_BGR2GRAY);blur(grayImg,edge,Size(8,10));Canny(edge, edge,3,9,3);imshow("边缘检测后", edge);waitKey(0);return0;}