4. 在一个画图程序里,例如PowerPoint,画一系列同心圆形成一个靶心
a.构造一系列进入靶心的直线,保存图像
b.用一个3*3的中孔大小,对你的图像运行并显示一阶x和y方向的层数,
然后将中孔大小增加到5*5,9*9和13*13. 描述结果
#include <cv.h> #include <highgui.h> #include <cxcore.h> #include <iostream> using namespace std; const CvSize size = cvSize(700,700); void fun4() { IplImage *src = cvCreateImage(size,IPL_DEPTH_8U,1); cvZero(src); CvRNG rng_state = cvRNG(-1); for(int r = 100; r < MIN(size.height/2,size.width/2); r += 40){ int thickness = MAX(10*cvRandReal(&rng_state),1); cvCircle(src,cvPoint(size.width/2,size.height/2),r,CV_RGB(255,255,255),thickness); } cvShowImage("src_a",src); for(double alpha = 0;alpha < 2*CV_PI ;alpha += CV_PI/6){ CvPoint pt1,pt2; int r = MIN(size.width/2,size.height/2); pt1 = cvPoint(size.height/2,size.width/2); pt2 = cvPoint(pt1.x + r*cos(alpha),pt1.y - r*sin(alpha)); int thickness = MAX(5*cvRandReal(&rng_state),1); cvLine(src,pt1,pt2,CV_RGB(255,255,255),thickness); } cvShowImage("src_b",src); cvWaitKey(); const int aperture[4] = {3,5,9,13}; IplImage *dst = cvCreateImage(size,IPL_DEPTH_16S,1); cvZero(dst); for(int i = 0; i<4 ;i++){ #if 1 char title_x[20],title_y[20]; sprintf(title_x,"dst_x_%1d*%1d",aperture[i],aperture[i]); sprintf(title_y,"dst_y_%1d*%1d",aperture[i],aperture[i]); cvSobel(src,dst,1,0,aperture[i]); cvShowImage(title_x,dst); cvSobel(src,dst,0,1,aperture[i]); cvShowImage(title_y,dst); #else char title[20]; sprintf(title,"dst_1d*%1d",aperture[i],aperture[i]); cvSobel(src,dst,1,1,aperture[i]); cvShowImage(title,dst); } #endif cvWaitKey(0); cvReleaseImage(&src); cvReleaseImage(&dst); cvDestroyAllWindows(); }