原创-EMGUCV的模板匹配与跟踪完成啦_第1页
原创-EMGUCV的模板匹配与跟踪完成啦_第2页
原创-EMGUCV的模板匹配与跟踪完成啦_第3页
原创-EMGUCV的模板匹配与跟踪完成啦_第4页
原创-EMGUCV的模板匹配与跟踪完成啦_第5页
已阅读5页,还剩8页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、原创-EMGUCV的模板匹配与跟踪完成啦!兄弟们好!经过很多天的努力学习,我的EMGUCV模板匹配完成了,用实际的摄像头取图象,再存为模板后,就能实现物体跟踪,还能进行相机上马达进行位置确定。好玩吧!弄两幅图来看下。这是匹配的,还能过行坐标二次定位。umg帆曲”项目如生虑小郦制普1R(X)面试,后,和口取懵下利Q0*李基温生视T坐标二次定位的H是跟肝旺看无点怦色耳给蓝IesO-h6届*jatec1匚*ttecPi等s®3"妙事事这是跟踪的QlicroioftVoid5115.doclicrosoftford:文件Q)««(I)IflSd)曲人(D格式Q)

2、IA5)安格«(!)«Sth(Mi:运用白卜自选圉箔op,、口o.aa闻iT_,士三三_以1页i节I”(ui251*fi列英语,0)aS>打开图片我的WMA也珞亢W工具口1福如WQd,碑助制生成横祗耳景打开相机7到-SJ密L以下为代码,只有自己写的部分,由软件生成的部分没有帖上usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Text;usingS

3、ystem.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:F

4、ormpublicImage<Bgr,byte>src;publicImage<Bgr,byte>tempsrc;publicForm1()InitializeComponent();privatevoidbutton1_Click(objectsender,EventArgse)OpenFileDialogof=newOpenFileDialog();of.Filter="(jpg)|*.jpg"if(of.ShowDialog()=DialogResult.OK)Image<Bgr,byte>imsrc=newImage<Bgr

5、,byte>(of.FileName);imageBox2.Image=imsrc;src=imsrc;imageBox1.Image=null;privatevoidbutton2_Click(objectsender,EventArgse)if(src!=null)不可直接将src符值给新建Image<Bgr,byte>imgsrc=src.Clone();图象,它传的只是一个地址,不是数据,要先考贝后才能不再引响原图像Image<Gray,byte>imggray=imgsrc.Convert<Gray,byte>();Image<Gray

6、,byte>imgthread=imggray.ThresholdBinary(newGray(60),newGray(255);Image<Gray,byte>imgcanny=imgthread.Canny(130,255);/Contour<Point>contour=imgcanny.FindContours();/这个函数用来找中间的轮廓的每一个点,是一个数组点,很多个才能组成一个圆。CircleF口cf=imgthread.HoughCircles(newGray(130),newGray(255),10,1,1,400)0;MCvFontmf=new

7、MCvFont(FONT.CV_FONT_HERSHEY_COMPLEX,1,1);if(cf.Length>0)cf0.Radius=cf0.Radius+50;imgsrc.Draw(cf0,newBgr(0,0,255),2);Rectanglerec=newRectangle(int)(cf0.Center.X-cf0.Radius),(int)(cf0.Center.Y-cf0.Radius),(int)(cf0.Radius*2),(int)(cf0.Radius*2);imgsrc.Draw(rec,newBgr(0,0,255),2);imgsrc.Draw(cf0.Ce

8、nter.ToString()+","+cf0.Radius.ToString(),refmf,newPoint(0,src.Height-30),newBgr(0,0,255);Image<Bgr,byte>templatebgr=src.Clone();Image<Bgr,byte>temp1=templatebgr.GetSubRect(rec).Clone();imageBox1.Image=temp1;temp1.Save("e:template.jpg");tempsrc=temp1.Clone();MessageBo

9、x.Show("模板生成成功!已保存到e:template.jpg中");)elseimgsrc.Draw("Dn'tfindoutcircle!PLStryagina.",refmf,newPoint(0,src.Height-30),newBgr(0,0,255);imageBox1.Image=imgcanny;)privatevoidbutton3_Click(objectsender,EventArgse)Image<Gray,byte>imgsrc=src.Convert<Gray,byte>().Clone(

10、);Image<Bgr,byte>readimg=newImage<Bgr,byte>("e:template.jpg");Image<Gray,byte>template=readimg.Convert<Gray,byte>().Clone();Image<Bgr,byte>imgcolor=src.Clone();Image<Gray,byte>imgresult=imgsrc.MatchTemplate(template,TM_TYPE.CV_TM_CCOEFF).Convert<Gray,

11、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);MCvFontmf=newMCvFont(FONT.CV_FONT_HERS

12、HEY_COMPLEX,1,1);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

13、max,min;Pointmaxl,minl;image.MinMax(outmin,outmax,outminl,outmaxl);if(tmtype=TM_TYPE.CV_TM_SQDIFF|tmtype=TM_TYPE.CV_TM_SQDIFF_NORMED)bestvalue=min0;bestpoint=minl0;elsebestvalue=max0;bestpoint=maxl0;privateboolmousestatus=false;privatePointstartpoint;privatePointendpoint;privateRectanglerectcurrent;

14、privatevoidimageBox2_MouseDown(objectsender,MouseEventArgse)if(imageBox2.Image!=null)startpoint.X=e.X;startpoint.Y=e.Y;mousestatus=true;privatevoidimageBox2_MouseUp(objectsender,MouseEventArgse)(if(mousestatus)(endpoint.X=e.X;endpoint.Y=e.Y;mousestatus=false;)privatevoidimageBox2_MouseMove(objectsen

15、der,MouseEventArgse)(if(mousestatus)(endpoint.X=e.X;endpoint.Y=e.Y;Rectanglerec1=newRectangle(startpoint,newSize(Math.Abs(startpoint.X-endpoint.X),Math.Abs(startpoint.Y-endpoint.Y);Image<Bgr,byte>imgdraw=src.Clone();imgdraw.Draw(rec1,newBgr(0,255,0),2);imageBox2.Image=imgdraw;rectcurrent=rec1;

16、imgdraw.Dispose();)privatevoidbutton4_Click(objectsender,EventArgse)(if(rectcurrent!=null)(Image<Bgr,byte>imgsrc=src.Clone();Image<Bgr,byte>redo=imgsrc.GetSubRect(rectcurrent);redo.Save("e:template.jpg");)Capturect=newCapture(0);privatevoidbutton5_Click(objectsender,EventArgse)

17、(if(ct!=null)(Application.Idle+=newEventHandler(GetFrame);)privatevoidGetFrame(objectsender,EventArgse)(Image<Bgr,byte>fram=ct.QueryFrame();imageBox2.Image=fram;src=fram;if(captureflg=true)(Image<Gray,byte>imgsrc=src.Convert<Gray,byte>().Clone();Image<Bgr,byte>readimg=tempsrc

18、;Image<Gray,byte>template=readimg.Convert<Gray,byte>().Clone();Image<Bgr,byte>imgcolor=src.Clone();Image<Gray,byte>imgresult=imgsrc.MatchTemplate(template,_TYPE.CV_TM_CCOEFF).Convert<Gray,byte>().Clone();imageBox1.Image=imgresult;doublebestvalue;bestvalue,outbestpoint.Y

19、),Pointbestpoint;FindBestPoint(imgresult,TM_TYPE.CV_TM_CCOERFjtbestpoint);Rectanglerec1=newRectangle(newPoint(bestpoint.X,template.Size);imgcolor.Draw(rec1,newBgr(0,0,255),2);imageBox1.Image=imgcolor;)Thread.Sleep(1);)privatevoidbutton6_Click(objectsender,EventArgse)(Application.Idle-=newEventHandler(G

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论