资源描述:
《常大OPENCV(图像处理参考函数)》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、学号:XXXXXXXXXXX作业报告XXXXX学院(系):信息、数理学院专业班级:应数1311、彩色图像转换为灰度图像Jtincludc"highgui.h〃ftinclude#includeintmain(intargc,char*argv[]){constchar*imagename=〃len&jpg〃;TplImage*img=cvLoadTmage(imagename);if(!img)fprintf(stderr,/zCannotloadimage%s〃,imagename);returnT;if(!img->imageDa
2、ta)//检查是否正确载入图像return-1;cvNamedWindow^image",CV_WINDOW_AUTOS1ZE);〃创建窗口cvShowImage(z,imagez,,img);//显示图像TplImage*imgl二cvCreateTmage(cvGetSize(img),TPLDEPTH8U,1);//创建目标图像cvCvtColor(img,imgl,CV_BGR2GRAY);//cvCvtColor(src,des,CV_BGR2GRAY)一_cvNamedWindow(,/gray_image,/,CV_WINDOW_AUTOSIZE);//
3、创建显示口标的窗口cvShowImage(z,gray_image/z,imgl);//显示灰度图像cvWaitKey();cvRclcaselmagc(&img);cvReleaselmage(&imgl);cvDestroyAllWindows();return0;}2、灰度图像反色#include#include
4、AR*data;inti,j,k;if(argc<2){”printf("Usage:TnvTmage7");exit(0);}img=cvLoadImage(argv[1]);if(!img){printf("Couldnotloadimagefile:%s,3rgv[l]);exit(0);height二img-〉height;width二img->width;step=img->widthStep;charmcls二img->nCharrncIs;data二(UCHAR*)img->imageData;printf(^P
5、rocessinga%d^%dimagewith%dchannels〃,height,width,channels);cvNamcdWindow(z,mainWin",CV_WINDOW_AUTOSIZE);cvMoveWindow(,zmainWin,100,100);for(i=0;i6、cvWaitKey(0);cvReleaselmage(&img);return0;3、彩色图像灰度化后二值化#inelude#inelude#include#ineludeusingnamespacestd;//声明图像IplImage指针TplImage*pSrclmg二NULL;IplImage*pGrayImg=NULL;IplImage*pBinarylmg=NULL;intThresh=127;//初始化滑动条位置〃滑动条响应函数voidonTrackcrSlid(intthresh
7、){//将图像转化为二值图pBinaryImg=cvCreatelmage(cvGetSize(pSrcImg),pSrcImg->depth,pSrdmg->nChannels);cvCopy(pSrcImg,pBinarylmg);//复制图像数据CvScalarscalar;intavg;for(inti二0;iheight;i++){for(intj=0;jwidth;j++){scalar=cvGet2D(pBinarylmg,i,j);//获取点(i,j)的像素avg=(scalar,v