資源簡介
ex6btr.zip

代碼片段和文件信息
#include?“cv.h“
#include?“highgui.h“
#include?“stdio.h“
#include?“math.h“
#include?“iostream.h“
int?main()
{
//-----------------------------------開創內存空間,載入圖像--------------------------------
IplImage??*img*gimg*edge*cedge*rimg*result1*result2*result3;//*result4;
img=cvLoadImage(“水果1.jpg“);
cvNamedWindow(“水果“1);
cvShowImage(“水果“img);
int?N_line=0;
int?count=0;
gimg=cvCreateImage(cvSize(img->widthimg->height)81);
????edge=cvCreateImage(cvSize(img->widthimg->height)81);
cedge=cvCreateImage(cvSize(img->widthimg->height)81);
rimg=cvCreateImage(cvSize(img->widthimg->height)81);
cvNot(rimgrimg);
result1=cvCreateImage(cvSize(img->widthimg->height)81);
result2=cvCreateImage(cvSize(img->widthimg->height)81);
result3=cvCreateImage(cvSize(img->widthimg->height)81);
cvNot(result1result1);
cvNot(result2result2);
cvNot(result3result3);
//------------------------圖像閾值化處理----------------------------------------
cvCvtColor(imggimgCV_BGR2GRAY);//灰度圖轉化
????
cvSmooth(gimgedgeCV_BLUR330);//高斯模糊
cvDilate(gimggimgNULL1);
cvNamedWindow(“灰度圖像“1);
cvShowImage(“灰度圖像“gimg);
CvMemStorage?*store;
CvSeq??*outline;
double?thread=200;//設立閾值
cvSmooth(gimgedgeCV_BLUR330);
cvNot(gimgedge);
cvThreshold(gimgedgethread255CV_THRESH_BINARY);
cvNot(edgeedge);
IplConvKernel?*space=cvCreateStructuringElementEx(4422CV_SHAPE_ELLIPSENULL);
????cvDilate(edgeedgespace1);
cvErode(edgeedgespace1);
cvNamedWindow(“二值圖像“1);
cvShowImage(“二值圖像“edge);
//------------------------邊緣提取----------------------------------------
cvCanny(edgecedgethreadthread*73);
// cvThreshold(gimgedge(double)edge_t255CV_THRESH_BINARY);
store=cvCreateMemStorage(0);
cvCreateSeq(CV_SEQ_ELTYPE_POINTsizeof(CvSeq)sizeof(CvPoint)store);
N_line=cvFindContours(cedgestore&outlinesizeof(CvContour)CV_RETR_LISTCV_CHAIN_APPROX_SIMPLEcvPoint(00));
????cout<<“?the?number?of?outline:“< // printf(“nCon=%d“nCon);
//------------------------建立分類標準,圖像分類----------------------------------------
for(;outline;outline=outline->h_next)
{
if(outline->total<8)
????????continue;
if(count%2==0)
{
cvDrawContours(rimgoutlineCV_RGB(000)CV_RGB(000)018cvPoint(00));
cvNamedWindow(“邊緣輪廓“1);
cvShowImage(“邊緣輪廓“rimg);
double?arealength;
area=(cvContourArea(outlineCV_WHOLE_SEQ)+fabs(cvContourArea(outline->h_nextCV_WHOLE_SEQ)));
area/=2;
length=(cvArcLength(outlineCV_WHOLE_SEQ-1)+fabs(cvArcLength(outline->h_nextCV_WHOLE_SEQ-1)));
length/=2;
printf(“\n?area=%f\n?length=%f\n“arealength);
double?roundper;
roundper=4*3.14*fabs(area)/(fabs(length)*fabs(length));
printf(“?roundper=%5f\n“roundper);
if(roundper<0.6&&area>=4000)
{
cvDrawContours(result1outlineCV_RGB(000)CV_RGB(000)0CV_FILLED8cvPoint
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2012-10-20?12:11??水果識別\
?????文件????????4100??2012-06-13?17:19??水果識別\123.cpp
?????文件???????34860??2012-06-08?16:03??水果識別\水果1.jpg
評論
共有 條評論