• 大小: 0.03M
    文件类型: .zip
    金币: 1
    下载: 0 次
    发布日期: 2021-06-08
  • 语言: 其他
  • 标签: 其他  

资源简介

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

评论

共有 条评论