OPENCV实现的轮廓检测与处理.docx

OPENCV实现的轮廓检测与处理.docx

ID:57890592

大小:15.27 KB

页数:6页

时间:2020-09-02

OPENCV实现的轮廓检测与处理.docx_第1页
OPENCV实现的轮廓检测与处理.docx_第2页
OPENCV实现的轮廓检测与处理.docx_第3页
OPENCV实现的轮廓检测与处理.docx_第4页
OPENCV实现的轮廓检测与处理.docx_第5页
资源描述:

《OPENCV实现的轮廓检测与处理.docx》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、////Thefull"SquareDetector"program.//Itloadsseveralimagessubsequentallyandtriestofindsquaresin//eachimage//#ifdef_CH_#pragmapackage#endif#ifndef_EiC#include"cv.h"#include"highgui.h"#include#include#include#endifintthresh=50;IplImage*img=0;IplImage*img0=0;CvMemStor

2、age*storage=0;CvPointpt[4];constchar*wndname="SquareDetectionDemo";//helperfunction://findsacosineofanglebetweenvectors//frompt0->pt1andfrompt0->pt2doubleangle(CvPoint*pt1,CvPoint*pt2,CvPoint*pt0){doubledx1=pt1->x-pt0->x;doubledy1=pt1->y-pt0->y;doubledx2=pt2->x-pt0->x;doubledy2=pt2->y-pt0->y;return

3、(dx1*dx2+dy1*dy2)/sqrt((dx1*dx1+dy1*dy1)*(dx2*dx2+dy2*dy2)+1e-10);}//returnssequenceofsquaresdetectedontheimage.//thesequenceisstoredinthespecifiedmemorystorageCvSeq*findSquares4(IplImage*img,CvMemStorage*storage){CvSeq*contours;inti,c,l,N=11;CvSizesz=cvSize(img->width&-2,img->height&-2);IplImage*t

4、img=cvCloneImage(img);//makeacopyofinputimageIplImage*gray=cvCreateImage(sz,8,1);IplImage*pyr=cvCreateImage(cvSize(sz.width/2,sz.height/2),8,3);IplImage*tgray;CvSeq*result;doubles,t;//createemptysequencethatwillcontainpoints-//4pointspersquare(thesquare'svertices)CvSeq*squares=cvCreateSeq(0,sizeof(

5、CvSeq),sizeof(CvPoint),storage);//selectthemaximumROIintheimage//withthewidthandheightdivisibleby2cvSetImageROI(timg,cvRect(0,0,sz.width,sz.height));//down-scaleandupscaletheimagetofilteroutthenoisecvPyrDown(timg,pyr,7);cvPyrUp(pyr,timg,7);tgray=cvCreateImage(sz,8,1);//findsquaresineverycolorplaneo

6、ftheimagefor(c=0;c<3;c++){//extractthec-thcolorplanecvSetImageCOI(timg,c+1);cvCopy(timg,tgray,0);//tryseveralthresholdlevelsfor(l=0;l

7、o0(whichforcesedgesmerging)cvCanny(tgray,gray,0,thresh,5);//dilatecannyoutputtoremovepotential//holesbetweenedgesegmentscvDilate(gray,gray,0,1);}else{//applythresholdifl!=0://tgray(x,y)=gray(x,y)<(l+1)*255/

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。