版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、原創(chuàng)-EMGUCV的模板匹配與跟蹤完成啦!兄弟們好!經(jīng)過很多天的努力學(xué)習(xí),我的EMGUCV模板匹配完成了,用實際的攝像頭取圖象,再存為模板后,就能實現(xiàn)物體跟蹤,還能進行相機上馬達進行位置確定。好玩吧!弄兩幅圖來看下。這是匹配的,還能過行坐標二次定位。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節(jié)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();圖象,它傳的只是一個地址,不是數(shù)據(jù),要先考貝后才能不再引響原圖像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();/這個函數(shù)用來找中間的輪廓的每一個點,是一個數(shù)組點,很多個才能組成一個圓。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. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 基于智能技術(shù)的學(xué)校公寓設(shè)施的設(shè)計與建設(shè)標準研究
- 結(jié)合心理健康的孕哺期婦女營養(yǎng)研究
- 科技創(chuàng)新引領(lǐng)下的現(xiàn)代農(nóng)業(yè)產(chǎn)業(yè)發(fā)展研究報告
- 防火意識教育在企業(yè)的長遠意義與發(fā)展趨勢分析
- 綠色科技在家庭節(jié)約中的應(yīng)用
- 教育行業(yè)安全事故案例分析與反思
- 2025年貴州裝備制造職業(yè)學(xué)院高職單招職業(yè)技能測試近5年??及鎱⒖碱}庫含答案解析
- 探索科技與金融結(jié)合的農(nóng)村養(yǎng)老服務(wù)路徑
- 足球比賽中的射門與防守技巧詳解
- 科技驅(qū)動的辦公設(shè)備產(chǎn)業(yè)鏈優(yōu)化
- 李克勤紅日標準粵語注音歌詞
- 職業(yè)健康監(jiān)護評價報告編制指南
- 管理ABC-干嘉偉(美團網(wǎng)COO)
- 基于視覺的工業(yè)缺陷檢測技術(shù)
- 軍事英語詞匯整理
- 家庭教育指導(dǎo)委員會章程
- DB31-T 1440-2023 臨床研究中心建設(shè)與管理規(guī)范
- 老客戶維護方案
- 高處作業(yè)安全教育培訓(xùn)講義課件
- 萬科物業(yè)管理公司全套制度(2016版)
- 英語經(jīng)典口語1000句
評論
0/150
提交評論