1、,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(IplImage* &image,int threshold1,int
2、 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;width=img-width;step=img-wid
3、thStep;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,3);/FilterAV(img,3);FeatureT
4、rack(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 *)image2-imageData;/image2int m=(
5、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* &image,int k)/cvSmoothIplImage
6、 *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,image-height),image-depth,1)
7、;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;PixArrayj=PixArrayj+1;PixArr
8、ayj+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,k);/CV_BLUR3*3/image=cvClon
9、eImage(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);corners2= cvCreateImage(cvGetSize(i
10、mage),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;