标签:
题目要求 |
程序代码 |
结果图片 |
拍两幅图片,两幅图片的拍摄位置略有不同,分别命名为src1和src2
a、将src1减去src2并求绝对值,记为diff12,理想情况下,diff12将使黑色
b、对diff12先腐蚀后膨胀
c、对diff12先膨胀后腐蚀
d、解释c和d结果图片的区别
1 // OpenCVExerciseTesting.cpp : 定义控制台应用程序的入口点。 2 // 3 //D:\\Work\\Work_Programming\\Source\\Image\\lena.jpg 4 5 6 #include "stdafx.h" 7 #include <cv.h> 8 #include <highgui.h> 9 #include <iostream> 10 using namespace cv; 11 using namespace std; 12 //函数声明-->--->-->--->-->--->-->--->// 13 14 15 16 //<--<--<--<--<--<--<--<--<--函数声明// 17 18 int _tmain(int argc, _TCHAR* argv[]) 19 { 20 const char * fileName1 = "D:\\Work\\Work_Programming\\Source\\Image\\临时\\鼠标1.jpg"; 21 const char * fileName2 = "D:\\Work\\Work_Programming\\Source\\Image\\临时\\鼠标2.jpg"; 22 IplImage * src1 = cvLoadImage(fileName1, CV_LOAD_IMAGE_UNCHANGED); 23 IplImage * src2 = cvLoadImage(fileName2, CV_LOAD_IMAGE_UNCHANGED); 24 assert(src1); 25 assert(src2); 26 27 //IplImage * img = cvCreateImage(cvSize(100, 100), IPL_DEPTH_8U, 1); 28 //assert(img); 29 //cvZero(img); 30 //cvSetReal2D(img, 49, 49, 255); 31 32 cvNamedWindow("原始图像1", 0); 33 cvNamedWindow("原始图像2", 0); 34 cvNamedWindow("题目_a", 0); 35 cvNamedWindow("题目_b", 0); 36 cvNamedWindow("题目_c", 0); 37 //cvNamedWindow("题目_d", 0); 38 39 /*char * imageName = "E:\\Testing\\Image\\ExerciseWindow.jpg"; 40 cvSaveImage(imageName, img);*/ 41 cvShowImage("原始图像1", src1); 42 cvShowImage("原始图像2", src2); 43 44 //---------------------------a:开始--------------------------------// 45 46 IplImage * diff12 = cvCloneImage(src1); 47 cvZero(diff12); 48 49 cvAbsDiff(src1, src2, diff12); 50 cvShowImage("题目_a", diff12); 51 52 /*char * saveName = "E:\\Testing\\Image\\SavePath\\diff12.jpg"; 53 cvSaveImage(saveName, diff12);*/ 54 55 //---------------------------a:结束--------------------------------// 56 57 58 //---------------------------b:开始--------------------------------// 59 60 IplImage * cleandiff = cvCloneImage(diff12); 61 cvZero(cleandiff); 62 63 cvErode(diff12, cleandiff); 64 cvDilate(diff12, cleandiff); 65 cvShowImage("题目_b", cleandiff); 66 67 /*saveName = "E:\\Testing\\Image\\SavePath\\image_open.jpg"; 68 cvSaveImage(saveName, cleandiff);*/ 69 70 //---------------------------b:结束--------------------------------// 71 72 //---------------------------c:开始--------------------------------// 73 74 IplImage * dirtydiff = cvCloneImage(diff12); 75 cvZero(dirtydiff); 76 77 cvDilate(diff12, dirtydiff); 78 cvErode(diff12, dirtydiff); 79 cvShowImage("题目_c", dirtydiff); 80 81 /*saveName = "E:\\Testing\\Image\\SavePath\\image_close.jpg"; 82 cvSaveImage(saveName, dirtydiff);*/ 83 84 //---------------------------c:结束--------------------------------// 85 86 cvWaitKey(0); 87 88 cvReleaseImage(&src1); 89 cvReleaseImage(&src2); 90 cvReleaseImage(&diff12); 91 cvReleaseImage(&cleandiff); 92 cvReleaseImage(&dirtydiff); 93 94 cvDestroyWindow("原始图像1"); 95 cvDestroyWindow("原始图像2"); 96 cvDestroyWindow("题目_a"); 97 cvDestroyWindow("题目_b"); 98 cvDestroyWindow("题目_c"); 99 //cvDestroyWindow("题目_d"); 100 101 102 return 0; 103 } 104
标签:
原文地址:http://www.cnblogs.com/tingshuixuan2012/p/4439482.html