原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx
- 文档编号:16113831
- 上传时间:2022-11-20
- 格式:DOCX
- 页数:10
- 大小:583.32KB
原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx
《原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx》由会员分享,可在线阅读,更多相关《原创EMGUCV的模板匹配与跟踪完成啦Word格式.docx(10页珍藏版)》请在冰豆网上搜索。
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];
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 原创 EMGUCV 模板 匹配 跟踪 完成