OpenCV——图像处理入门:膨胀与腐蚀、图像模糊、边缘检测

全部外部依赖项:

 1 opencv_aruco341d.lib
 2 opencv_bgsegm341d.lib
 3 opencv_calib3d341d.lib
 4 opencv_bioinspired341d.lib
 5 opencv_ccalib341d.lib
 6 opencv_core341d.lib
 7 opencv_datasets341d.lib
 8 opencv_dnn_objdetect341d.lib
 9 opencv_dnn341d.lib
10 opencv_dpm341d.lib
11 opencv_face341d.lib
12 opencv_features2d341d.lib
13 opencv_flann341d.lib
14 opencv_fuzzy341d.lib
15 opencv_hfs341d.lib
16 opencv_highgui341d.lib
17 opencv_img_hash341d.lib
18 opencv_imgcodecs341d.lib
19 opencv_imgproc341d.lib
20 opencv_line_descriptor341d.lib
21 opencv_ml341d.lib
22 opencv_objdetect341d.lib
23 opencv_optflow341d.lib
24 opencv_phase_unwrapping341d.lib
25 opencv_photo341d.lib
26 opencv_plot341d.lib
27 opencv_reg341d.lib
28 opencv_saliency341d.lib
29 opencv_shape341d.lib
30 opencv_stereo341d.lib
31 opencv_rgbd341d.lib
32 opencv_stitching341d.lib
33 opencv_structured_light341d.lib
34 opencv_superres341d.lib
35 opencv_surface_matching341d.lib
36 opencv_text341d.lib
37 opencv_tracking341d.lib
38 opencv_video341d.lib
39 opencv_videoio341d.lib
40 opencv_videostab341d.lib
41 opencv_xfeatures2d341d.lib
42 opencv_xobjdetect341d.lib
43 opencv_xphoto341d.lib

测试程序:

 1 #include 
 2 #include 
 3 using namespace cv;
 4 
 5 int main(int argc, char** argv)
 6 {
 7     Mat srcImage = imread("test.jpg");
 8 
 9     imshow("[My Picture]", srcImage);
10 
11     waitKey(0);
12 
13 }

膨胀和腐蚀:

 OpenCV——图像处理入门:膨胀与腐蚀、图像模糊、边缘检测_第1张图片

 1 #include 
 2 #include 
 3 //#include 
 4 //#include 
 5 using namespace cv;
 6 
 7 int main(int argc, char** argv)
 8 {
 9     Mat srcImage = imread("test.jpg");
10     imshow("[原图]", srcImage);
11 
12     //进行膨胀操作
13     Mat element1 = getStructuringElement(MORPH_RECT, Size(5, 5));
14     Mat dstImage1;
15     dilate(srcImage, dstImage1, element1);
16     imshow("[膨胀效果图]", dstImage1);
17 
18     //进行腐蚀操作
19     Mat element2 = getStructuringElement(MORPH_RECT, Size(5, 5));
20     Mat dstImage2;
21     erode(srcImage, dstImage2, element2);
22     imshow("[腐蚀效果图]", dstImage2);
23 
24     waitKey(0);
25 
26     return 0;
27 }

图像模糊:

OpenCV——图像处理入门:膨胀与腐蚀、图像模糊、边缘检测_第2张图片

OpenCV——图像处理入门:膨胀与腐蚀、图像模糊、边缘检测_第3张图片 

 1 #include 
 2 #include 
 3 //#include 
 4 //#include 
 5 using namespace cv;
 6 
 7 int main(int argc, char** argv)
 8 {
 9     Mat srcImage = imread("test.jpg");
10     imshow("[原图]", srcImage);
11 
12     //进行均值滤波操作
13     Mat dstImage1;
14     blur(srcImage, dstImage1, Size(7,7));
15     imshow("[效果图]", dstImage1);
16 
17     waitKey(0);
18 
19     return 0;
20 }

Canny边缘检测:

OpenCV——图像处理入门:膨胀与腐蚀、图像模糊、边缘检测_第4张图片

 1 #include 
 2 #include 
 3 //#include 
 4 //#include 
 5 using namespace cv;
 6 
 7 //Canny边缘检测
 8 int main(int argc, char** argv)
 9 {
10     Mat srcImage = imread("test.jpg");
11     imshow("[原图]", srcImage);
12 
13     Mat edge, gray;
14     //将原图转换成灰度图像
15     cvtColor(srcImage, gray, COLOR_BGR2GRAY);
16     //均值滤波降噪
17     blur(gray, edge, Size(3, 3));
18     //运行Canny算子
19     Canny(edge, edge, 3, 9, 3);
20 
21 
22     imshow("[效果图]", edge);
23 
24     waitKey(0);
25 
26     return 0;
27 }

 

你可能感兴趣的:(OpenCV——图像处理入门:膨胀与腐蚀、图像模糊、边缘检测)