原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx

上传人:b****5 文档编号:16113831 上传时间:2022-11-20 格式:DOCX 页数:10 大小:583.32KB
下载 相关 举报
原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx_第1页
第1页 / 共10页
原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx_第2页
第2页 / 共10页
原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx_第3页
第3页 / 共10页
原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx_第4页
第4页 / 共10页
原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx_第5页
第5页 / 共10页
点击查看更多>>
下载资源
资源描述

原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx

《原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx》由会员分享,可在线阅读,更多相关《原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx(10页珍藏版)》请在冰豆网上搜索。

原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx

usingSystem.ComponentModel;

usingSystem.Data;

usingSystem.Drawing;

usingSystem.Linq;

usingSystem.Text;

usingSystem.Windows.Forms;

usingSystem.Threading;

usingSystem.IO;

usingSystem.Drawing.Imaging;

usingEmgu.CV;

usingEmgu.CV.Structure;

usingEmgu.CV.CvEnum;

usingEmgu.CV.Util;

usingEmgu.CV.UI;

usingEmgu.CV.VideoSurveillance;

usingEmgu.Util;

usingEmgu.Util.TypeEnum;

usingEmgu.CV.GPU;

namespace模板匹配

{

 

publicpartialclassForm1:

Form

{

publicImage<

Bgr,byte>

src;

tempsrc;

publicForm1()

InitializeComponent();

}

privatevoidbutton1_Click(objectsender,EventArgse)

OpenFileDialogof=newOpenFileDialog();

of.Filter="

(jpg)|*.jpg"

;

if(of.ShowDialog()==DialogResult.OK)

Image<

imsrc=newImage<

(of.FileName);

imageBox2.Image=imsrc;

src=imsrc;

imageBox1.Image=null;

privatevoidbutton2_Click(objectsender,EventArgse)

if(src!

=null)

imgsrc=src.Clone();

//不可直接将src符值给新建图象,它传的只是一个地址,不是数据,要先考贝后才能不再引响原图像

Gray,byte>

imggray=imgsrc.Convert<

();

imgthread=imggray.ThresholdBinary(newGray(60),newGray(255));

imgcanny=imgthread.Canny(130,255);

//Contour<

Point>

contour=imgcanny.FindContours();

//这个函数用来找中间的轮廓的每一个点,是一个数组点,很多个才能组成一个圆。

CircleF[]cf=imgthread.HoughCircles(newGray(130),newGray(255),10,1,1,400)[0];

MCvFontmf=newMCvFont(FONT.CV_FONT_HERSHEY_COMPLEX,1,1);

if(cf.Length>

0)

cf[0].Radius=cf[0].Radius+50;

imgsrc.Draw(cf[0],newBgr(0,0,255),2);

Rectanglerec=newRectangle((int)(cf[0].Center.X-cf[0].Radius),(int)(cf[0].Center.Y-cf[0].Radius),(int)(cf[0].Radius*2),(int)(cf[0].Radius*2));

imgsrc.Draw(rec,newBgr(0,0,255),2);

imgsrc.Draw(cf[0].Center.ToString()+"

"

+cf[0].Radius.ToString(),refmf,newPoint(0,src.Height-30),newBgr(0,0,255));

templatebgr=src.Clone();

Image<

Bgr,byte>

temp1=templatebgr.GetSubRect(rec).Clone();

imageBox1.Image=temp1;

temp1.Save(@"

e:

\template.jpg"

);

tempsrc=temp1.Clone();

MessageBox.Show(@"

模板生成成功!

已保存到e:

\template.jpg中"

else

imgsrc.Draw(@"

Dn'

tfindoutcircle!

PLStryagina."

refmf,newPoint(0,src.Height-30),newBgr(0,0,255));

imageBox1.Image=imgcanny;

privatevoidbutton3_Click(objectsender,EventArgse)

imgsrc=src.Convert<

().Clone();

readimg=newImage<

(@"

template=readimg.Convert<

imgcolor=src.Clone();

Gray,byte>

imgresult=imgsrc.MatchTemplate(template,TM_TYPE.CV_TM_CCOEFF).Convert<

Gray,byte>

().Clone();

imageBox1.Image=imgresult;

doublebestvalue;

Pointbestpoint;

FindBestPoint(imgresult,TM_TYPE.CV_TM_CCOEFF,outbestvalue,outbestpoint);

Rectanglerec1=newRectangle(newPoint(bestpoint.X,bestpoint.Y),template.Size);

imgcolor.Draw(rec1,newBgr(0,0,255),2);

imgcolor.Draw(rec1.X.ToString()+"

+rec1.Y.ToString(),refmf,newPoint(0,src.Height-30),newBgr(0,0,255));

imageBox1.Image=imgcolor 

publicvoidFindBestPoint(Image<

Gray,byte>

image,TM_TYPEtmtype,outdoublebestvalue,outPointbestpoint)

bestvalue=0d;

bestpoint=newPoint(0,0);

double[]max,min;

Point[]maxl,minl;

image.MinMax(outmin,outmax,outminl,outmaxl);

if(tmtype==TM_TYPE.CV_TM_SQDIFF||tmtype==TM_TYPE.CV_TM_SQDIFF_NORMED)

bestvalue=min[0];

bestpoint=minl[0];

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 高等教育 > 教育学

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1