1、中值滤波-均值滤波-边缘检测-角点检测-基于opencv,opencv.txt#include #include #include using namespace std;bool FilterAV(IplImage* &image,int k);bool FilterAV2(IplImage* &image,int k);bool FilterMid(IplImage* &image,int k);bool FilterMid2(IplImage* &image,int k);bool FeatureTrack(IplImage* &image);bool EdgeTrack(IplImag
2、e* &image,int threshold1,int threshold2);int main(int argc,char *argv)/argc*argvIplImage *img=0;int height,width,step,channels;uchar *data;/img=cvLoadImage(OpenCvDemo.jpg,0);/5img=cvLoadImage(OpenCvDemo.jpg,0);if (!img)printf(could not load image file: %sn,OpenCvDemo.jpg);exit(0);/height=img-height;
3、width=img-width;step=img-widthStep;channels=img-nChannels;data=(uchar*)img-imageData;printf(processing a %dx%d image with %d channelsn,height,width,channels);/cvNamedWindow(mainWin,CV_WINDOW_AUTOSIZE);cvMoveWindow(mainWin,100,100);/FilterAV2(img,3);/FilterAV(img,3);/FilterMid(img,3);/FilterMid2(img,
4、3);/FilterAV(img,3);FeatureTrack(img);/EdgeTrack(img,60,80);/cvShowImage(mainWin,img);/wait for a keycvWaitKey(0);/release the imagecvReleaseImage(&img);return 0;bool FilterAV(IplImage* &image,int k)/IplImage *image2=cvCreateImage(cvSize(image-width,image-height),image-depth,1);uchar *p=(uchar *)ima
5、ge2-imageData;/image2int m=(k-1)/2;for (int x=m;xheight-m;+x)for (int y=m;ywidth-m;+y)int SumData=0;for (int i=-m;im+1;+i)for (int j=-m;jimageData)(x+i)*image-widthStep+y+j;px*image-widthStep+y=SumData/(k*k);image=cvCloneImage(image2);/cvReleaseImage(&image2);/return true;bool FilterAV2(IplImage* &i
6、mage,int k)/cvSmoothIplImage *dstImage=0;dstImage=cvCreateImage(cvGetSize(image),image-depth,1);cvSmooth(image,dstImage,CV_BLUR,k,k);/CV_BLUR3*3image=cvCloneImage(dstImage);cvReleaseImage(&dstImage);return true;bool FilterMid(IplImage* &image,int k)/IplImage *image2=cvCreateImage(cvSize(image-width,
7、image-height),image-depth,1);uchar *ImagePix=(uchar *)image2-imageData;int m=(k-1)/2;for (int x=m;xheight-m;+x)for (int y=m;ywidth-m;+y)uchar PixArray100;int t=0;for (int i=-m;im+1;+i)for(int j=-m;jimageData)(x+i)*image-widthStep+y+j;for (int i=0;ik*k-1;+i)for(int j=0;jPixArrayj+1)uchar k=PixArrayj;
8、PixArrayj=PixArrayj+1;PixArrayj+1=k;ImagePixx*image-widthStep+y=PixArray(k*k-1)/2;image=cvCloneImage(image2);/cvReleaseImage(&image2);/return true;bool FilterMid2(IplImage* &image,int k)/IplImage *dstImage=0;/dstImage=cvCreateImage(cvGetSize(image),image-depth,1);/cvSmooth(image,dstImage,CV_MEDIAN,k
9、,k);/CV_BLUR3*3/image=cvCloneImage(dstImage);/cvReleaseImage(&dstImage);cvSmooth(image,image,CV_MEDIAN,k,k);return true; /bool FeatureTrack(IplImage* &image)CvPoint2D32f corners100000;int CornerCount=0;IplImage *corners1=0,*corners2=0;corners1= cvCreateImage(cvGetSize(image), image-depth, 1);corners
10、2= cvCreateImage(cvGetSize(image),image-depth, 1);cvGoodFeaturesToTrack(image,corners1,corners2,corners,&CornerCount,0.05,20,0);coutTrack over!;/ draw circles at each corner location in the gray image and/ print out a list the cornersfor (int i=0;idepth,1);/cvNot(image,edge);/,cvCanny(image,image,threshold1,threshold2,3);/threshold1,threshold2/imagereturn true;
©2010-2025 宁波自信网络信息技术有限公司 版权所有
客服电话:4008-655-100 投诉/维权电话:4009-655-100