cvSmooth(imgMain,imgMain);
cvCvtColor(imgMain,imgGray,CV_BGR2GRAY);
cvCanny( imgGray, imgCanny, 50, 250);
cvDilate(imgCanny,imgCanny); //合併小區域.
cvThreshold(imgCanny,imgCanny,50.0,255,CV_THRESH_BINARY);//設定輪廓閾值
cvSaveImage("testImageA.bmp",imgMain);
double area=0;
CvMemStorage * storage = cvCreateMemStorage(0);
CvSeq * contour = 0;
int mode = CV_RETR_EXTERNAL;
contour = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint) , storage);
cvFindContours(imgCanny, storage, &contour, sizeof(CvContour), mode, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
cvDrawContours(imgDst, contour, CV_RGB(0,0,255), CV_RGB(255, 0, 0), 2, 2, 8, cvPoint(0,0));
//
int area_num=0;
for( CvSeq* c = contour; c != 0; c = c->h_next )
{
area = cvContourArea(c);
area=area;
area_num++;
stboxMessage->Items->Add(String::Format( "The area of patern : {0}", area ));
}
cvCvtColor(imgMain,imgGray,CV_BGR2GRAY);
cvCanny( imgGray, imgCanny, 50, 250);
cvDilate(imgCanny,imgCanny); //合併小區域.
cvThreshold(imgCanny,imgCanny,50.0,255,CV_THRESH_BINARY);//設定輪廓閾值
cvSaveImage("testImageA.bmp",imgMain);
double area=0;
CvMemStorage * storage = cvCreateMemStorage(0);
CvSeq * contour = 0;
int mode = CV_RETR_EXTERNAL;
contour = cvCreateSeq(CV_SEQ_ELTYPE_POINT, sizeof(CvSeq), sizeof(CvPoint) , storage);
cvFindContours(imgCanny, storage, &contour, sizeof(CvContour), mode, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));
cvDrawContours(imgDst, contour, CV_RGB(0,0,255), CV_RGB(255, 0, 0), 2, 2, 8, cvPoint(0,0));
//
int area_num=0;
for( CvSeq* c = contour; c != 0; c = c->h_next )
{
area = cvContourArea(c);
area=area;
area_num++;
stboxMessage->Items->Add(String::Format( "The area of patern : {0}", area ));
}
留言
張貼留言