新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
OpenCV實現(xiàn)最小外接正矩形的代碼示例-創(chuàng)新互聯(lián)
創(chuàng)新互聯(lián)www.cdcxhl.cn八線動態(tài)BGP香港云服務(wù)器提供商,新人活動買多久送多久,劃算不套路!
這篇文章主要講解了OpenCV實現(xiàn)最小外接正矩形的代碼示例,內(nèi)容清晰明了,對此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會有幫助。
#include "stdafx.h" #include "cv.h" #include "highgui.h" #include "cxcore.h" #include "math.h" #includeint main(int argc, char* argv[]) { IplImage *src; IplImage *dst; IplImage *ROI; CvMemStorage* storage=cvCreateMemStorage(0); CvSeq* contour=0; src=cvLoadImage("I:\\test.jpg",0); cvNamedWindow("image0",1); cvShowImage("image0",src); int hei=src->height; int wid=src->width; uchar *data; data=(uchar*)src->imageData; int widstep=src->widthStep; int channel=src->nChannels; dst=cvCreateImage(cvSize(wid,hei),IPL_DEPTH_8U,3); ROI=cvCreateImage(cvSize(wid,hei),IPL_DEPTH_8U,3); for (int i=0;i 120) { data[i*widstep+j*channel]=0; } else { data[i*widstep+j*channel]=255; } } } cvNamedWindow("image",0); cvShowImage("image",src); printf("圖像的高為:%d,寬為:%d\n\n",hei,wid); cvCvtColor(src, dst, CV_GRAY2BGR);; cvFindContours(src,storage,&contour,sizeof(CvContour),CV_RETR_CCOMP,CV_CHAIN_APPROX_SIMPLE); for(;contour!=0;contour=contour->h_next) { double length =cvArcLength(contour); double area =fabs(cvContourArea(contour)); CvRect rect = cvBoundingRect(contour,1); cout<<"Length="<
文章名稱:OpenCV實現(xiàn)最小外接正矩形的代碼示例-創(chuàng)新互聯(lián)
當(dāng)前URL:http://www.dlmjj.cn/article/gpjep.html