zw版_zw中文增强版Halcon官方Delphi例程
【《zw版·delphi与halcon系列原创教程》
zw版_zw中文增强版Halcon官方Delphi例程
源码下载:http://files.cnblogs.com/files/ziwang/zw_match.zip
2016 zw中文增强版(delph2007,HALCON 11.01)
主要改动之处:
:: 将位于窗口class的私有变量,改为全局变量,便于分析,修改
:: 增加大量中文注解
:: 将原版的批量自动测量,改为手动单幅测量,便于观测效果
:: 多处节点,增加图像文件输出,便于理解,观测运行效果
注意A点,这个是中文增强版,增加的单步多节点截图,可以清楚看到相关细节。
http:www.cnblogs.com/ziwang/
《zw版·Halcon-delphi系列原创教程》
--------------
全部源码如下
unit zw_match;
//
// HALCON/Delphi pattern matching and measure example
//
// 2016 zw中文增强版(delph2007,HALCON 11.01)
//
// 主要改动之处:
// :: 将位于窗口class的私有变量,改为全局变量,便于分析,修改
// :: 增加大量中文注解
// :: 将原版的批量自动测量,改为手动单幅测量,便于观测效果
// :: 多处节点,增加图像文件输出,便于理解,观测运行效果
// ::
// ::
//
// http://www.cnblogs.com/ziwang/
//《zw版·Halcon-delphi系列原创教程》
// interface uses
HALCONXLib_TLB,
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, StdCtrls, sMemo, ExtCtrls; type
Tmwin = class(TForm)
HXCtrl: THWindowXCtrl;
CopyrightLabel: TLabel;
msg: TsMemo;
Panel1: TPanel;
CreateBtn: TButton;
StartBtn: TButton;
MatchingScoreLabel: TLabel;
MatchingTimeLabel: TLabel;
MatchingLabel: TLabel;
MeasureDistLabel: TLabel;
MeasureNumLabel: TLabel;
MeasureTimeLabel: TLabel;
MeasureLabel: TLabel;
procedure FormShow(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure InitBtnClick(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure CreateBtnClick(Sender: TObject);
procedure StartBtnClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end; var
mwin: Tmwin;
xwin: HWindowX;
Framegrabber: HFramegrabberX;
Img, ImgReduced, ModelImage: HImageX;
RectangleRegion, ModelRegion, ModelRegionTrans: HRegionX;
Rectangle1, Rectangle2: HRegionX;
ShapeModel: HShapeModelX;
Matrix: HHomMat2DX;
Tuple: HTupleX;
Sys: HSystemX;
Measure1, Measure2: HMeasureX;
ImgWidth, ImgHeight: OleVariant;
Row, Column, Area: OleVariant;
Rect1Row, Rect1Col, Rect2Row, Rect2Col: Double;
RectPhi, RectLength1, RectLength2: Double; implementation {$R *.dfm} //------------------
procedure initData();
var dss:string;
begin
with mwin do begin //--------------
xwin.SetPart(,,,);//设置图像窗口尺寸
Img := Framegrabber.GrabImage();//从输入图像系列,加载图像
Img.DispObj(xwin);//显示图像
Img.WriteImage('png',,'tmp\ImgSr');
//---------检测图像尺寸
ImgWidth:=Img.GetImageSize(ImgHeight);
dss:='pic wid,hei:'+VarToStr(ImgWidth)+','+VarToStr(ImgHeight);msg.Lines.Add(dss);msg.Lines.Add('');
//--------- RectangleRegion.GenRectangle1(,,,);//设置检测区坐标(Row,Column,wid,hei)//??
xwin.SetColor('red');//设置矩形颜色
xwin.SetDraw('margin');//设置填充方式,margin,为边框模式,fill,为填充模式
xwin.SetLineWidth();//设置笔画粗细
RectangleRegion.DispObj(xwin);;//显示矩形box
//--------------
Area :=RectangleRegion.AreaCenter(Row,Column);//获取box区域面积,中心位置
dss:='Row,Column : 188,182';msg.Lines.Add(dss);
dss:='Row2,Column2 : 298,412';msg.Lines.Add(dss);
dss:='box区域面积area : '+VarToStr(area);msg.Lines.Add(dss);
dss:='box区域大小wid,hei : '+VarToStr(-+)+','+VarToStr(-+);msg.Lines.Add(dss);
dss:='box区域中心位置Row,Column : '+VarToStr(Row)+','+VarToStr(Column);msg.Lines.Add(dss);
//-------- 设置加工区参数
Rect1Row := Row - ;
Rect1Col := Column + ;
Rect2Row := Row + ;
Rect2Col := Column + ;
RectPhi := ;
RectLength1 := ;
RectLength2 := ;
end;
end; procedure createShapeModel(); //创建加工模型 ShapeModel
begin
with mwin do begin
//----设置显示窗口参数
xwin.SetColor('red');xwin.SetDraw('margin');xwin.SetLineWidth();
RectangleRegion.DispObj(xwin);
//----设置model图像
ImgReduced := Img.ReduceDomain(RectangleRegion);
ModelImage := ImgReduced.InspectShapeModel(ModelRegion,,);
//ImgReduced.WriteImage('png',0,'tmp\ImgReduced');
//ModelImage.WriteImage('png',0,'tmp\ModelImage');
xwin.DumpWindow('png','tmp\xwin_Shape01');
//------------建立辅助区域
Rectangle1.GenRectangle2(Rect1Row,Rect1Col,RectPhi,RectLength1,RectLength2);
Rectangle2.GenRectangle2(Rect2Row,Rect2Col,RectPhi,RectLength1,RectLength2);
//------------创建模型 ShapeModel
ShapeModel.CreateShapeModel(ImgReduced,,,Tuple.TupleRad(),
Tuple.TupleRad(),'none','use_polarity',,);
//----设置显示窗口参数
xwin.SetColor('green');xwin.SetDraw('fill');
ModelRegion.DispObj(xwin);
xwin.DumpWindow('png','tmp\xwin_Shape02');
xwin.SetColor('blue'); xwin.SetDraw('margin');
Rectangle1.DispObj(xwin);Rectangle2.DispObj(xwin);
xwin.DumpWindow('png','tmp\xwin_Shape03');
end;
end; procedure DoMeasurement;
var
S1, S2: Double;
RowCheck, ColumnCheck, AngleCheck, Score: OleVariant;
Rect1RowCheck, Rect1ColCheck, Rect2RowCheck, Rect2ColCheck: OleVariant;
RowEdgeFirst1, ColumnEdgeFirst1: OleVariant;
AmplitudeFirst1, RowEdgeSecond1: OleVariant;
ColumnEdgeSecond1, AmplitudeSecond1: OleVariant;
IntraDistance1, InterDistance1: OleVariant;
RowEdgeFirst2, ColumnEdgeFirst2: OleVariant;
AmplitudeFirst2, RowEdgeSecond2: OleVariant;
ColumnEdgeSecond2, AmplitudeSecond2: OleVariant;
IntraDistance2, InterDistance2: OleVariant;
MinDistance: OleVariant;
NumLeads: Longint;
dss:string;
begin
// 本demo,演示的是如何测量IC针脚间的距离
with mwin do begin
Sys.SetSystem('flush_graphic','false');//曲线系统图像自动刷新
Img := Framegrabber.GrabImage();//设置新图像
Img.Dispobj(xwin);//显示加工图像
//----注意,Mea00sr.png与 ImgSr.png的不同,旋转了一个角度
//----Framegrabber图像源是系列图片,通过旋转模拟加工现场,
//----每次调用GrabImage,会自动更新
xwin.DumpWindow('png','tmp\Mea00sr');
// Find the IC in the current image. 匹配模型
S1 := Sys.CountSeconds;
RowCheck := ShapeModel.FindShapeModel(Img,,Tuple.TupleRad(),0.7,,0.5,
'least_squares',,0.7,ColumnCheck,
AngleCheck,Score);
S2 := Sys.CountSeconds;
MatchingTimeLabel.Caption := Format('Time: %4.2f',[(S2-S1)*]);
MatchingScoreLabel.Caption := 'Score: ';
xwin.DumpWindow('png','tmp\Mea01');
//dss:=VarToStr(High(RowCheck));msg.lines.Add(dss);
//-----找到模型,开始测量
if not VarIsEmpty(RowCheck) and not VarIsArray(RowCheck) then begin
MatchingScoreLabel.Caption := Format('Score: %7.5f',[double(Score)]);
// Rotate the model for visualization purposes.旋转模型
Matrix.VectorAngleToRigid(Row,Column,,RowCheck,ColumnCheck,AngleCheck);
ModelRegionTrans := ModelRegion.AffineTransRegion(Matrix,'false');
xwin.SetColor('green');xwin.SetDraw('fill');
ModelRegionTrans.DispObj(xwin);
xwin.DumpWindow('png','tmp\Mea02');
// Compute the parameters of the measurement rectangles.
Rect1RowCheck := Matrix.AffineTransPixel(Rect1Row,Rect1Col,Rect1ColCheck);
Rect2RowCheck := Matrix.AffineTransPixel(Rect2Row,Rect2Col,Rect2ColCheck);
// For visualization purposes, generate the two rectangles as regions and
// display them.
Rectangle1.GenRectangle2(Rect1RowCheck,Rect1ColCheck,RectPhi+AngleCheck,
RectLength1,RectLength2);
Rectangle2.GenRectangle2(Rect2RowCheck,Rect2ColCheck,RectPhi+AngleCheck,
RectLength1,RectLength2);
xwin.SetColor('blue');xwin.SetDraw('margin');
Rectangle1.DispObj(xwin);Rectangle2.DispObj(xwin);
xwin.DumpWindow('png','tmp\Mea03');
// Do the actual measurements.开始测量
S1 := Sys.CountSeconds;
Measure1.GenMeasureRectangle2(Rect1RowCheck,Rect1ColCheck,
RectPhi+AngleCheck,RectLength1,RectLength2,
ImgWidth,ImgHeight,'bilinear');
Measure2.GenMeasureRectangle2(Rect2RowCheck,Rect2ColCheck,
RectPhi+AngleCheck,RectLength1,RectLength2,
ImgWidth,ImgHeight,'bilinear');
RowEdgeFirst1 := Measure1.MeasurePairs(Img,,,'positive','all',
ColumnEdgeFirst1,AmplitudeFirst1,
RowEdgeSecond1,ColumnEdgeSecond1,
AmplitudeSecond1,IntraDistance1,
InterDistance1);
RowEdgeFirst2 := Measure2.MeasurePairs(Img,,,'positive','all',
ColumnEdgeFirst2,AmplitudeFirst2,
RowEdgeSecond2,ColumnEdgeSecond2,
AmplitudeSecond2,IntraDistance2,
InterDistance2);
S2 := Sys.CountSeconds;
MeasureTimeLabel.Caption := Format('Time: %4.2f',[(S2-S1)*]);
xwin.SetColor('red');
xwin.DispLine(Tuple.TupleSub(RowEdgeFirst1,Tuple.TupleMult(RectLength2,Cos(AngleCheck))),
Tuple.TupleSub(ColumnEdgeFirst1,Tuple.TupleMult(RectLength2,Sin(AngleCheck))),
Tuple.TupleAdd(RowEdgeFirst1,Tuple.TupleMult(RectLength2,Cos(AngleCheck))),
Tuple.TupleAdd(ColumnEdgeFirst1,Tuple.TupleMult(RectLength2,Sin(AngleCheck))));
xwin.DumpWindow('png','tmp\Mea041');
xwin.DispLine(Tuple.TupleSub(RowEdgeSecond1,Tuple.TupleMult(RectLength2,Cos(AngleCheck))),
Tuple.TupleSub(ColumnEdgeSecond1,Tuple.TupleMult(RectLength2,Sin(AngleCheck))),
Tuple.TupleAdd(RowEdgeSecond1,Tuple.TupleMult(RectLength2,Cos(AngleCheck))),
Tuple.TupleAdd(ColumnEdgeSecond1,Tuple.TupleMult(RectLength2,Sin(AngleCheck))));
xwin.DumpWindow('png','tmp\Mea042');
xwin.DispLine(Tuple.TupleSub(RowEdgeFirst2,Tuple.TupleMult(RectLength2,Cos(AngleCheck))),
Tuple.TupleSub(ColumnEdgeFirst2,Tuple.TupleMult(RectLength2,Sin(AngleCheck))),
Tuple.TupleAdd(RowEdgeFirst2,Tuple.TupleMult(RectLength2,Cos(AngleCheck))),
Tuple.TupleAdd(ColumnEdgeFirst2,Tuple.TupleMult(RectLength2,Sin(AngleCheck))));
xwin.DumpWindow('png','tmp\Mea043');
xwin.DispLine(Tuple.TupleSub(RowEdgeSecond2,Tuple.TupleMult(RectLength2,Cos(AngleCheck))),
Tuple.TupleSub(ColumnEdgeSecond2,Tuple.TupleMult(RectLength2,Sin(AngleCheck))),
Tuple.TupleAdd(RowEdgeSecond2,Tuple.TupleMult(RectLength2,Cos(AngleCheck))),
Tuple.TupleAdd(ColumnEdgeSecond2,Tuple.TupleMult(RectLength2,Sin(AngleCheck))));
xwin.DumpWindow('png','tmp\Mea044');
NumLeads := (Tuple.TupleLength(IntraDistance1)+Tuple.TupleLength(IntraDistance2));
MeasureNumLabel.Caption := Format('Number of leads: %2d',[NumLeads]);
MinDistance := Tuple.TupleMin(Tuple.TupleConcat(InterDistance1,InterDistance2));
MeasureDistLabel.Caption := Format('Minimum lead distance: %6.3f',[double(MinDistance)]);
end;
xwin.DumpWindow('png','tmp\Mea09');
end;
Sys.SetSystem('flush_graphic','true');
// Force the graphics window to be updated by displaying an empty circle.
xwin.DispCircle(-,-,);
end; //------------------ procedure Tmwin.FormCreate(Sender: TObject);
begin
Set8087CW($27f);//设置FPU浮点计算参数,一般很少见
HXCtrl.ControlInterface.QueryInterface(IID_IHWindowX,xwin);//设置Halcon控件接口
Framegrabber := CoHFramegrabberX.Create;//设置图像输入,文件或相机
ShapeModel := CoHShapeModelX.Create;//创建匹配模型变量
//---------------
RectangleRegion := CoHRegionX.Create;//建立一个矩形,作为检测区
Rectangle1 := CoHRegionX.Create;//建立辅助测区
Rectangle2 := CoHRegionX.Create;//建立辅助测区 Matrix := CoHHomMat2DX.Create;//建立 矩阵变量,用于传递模型参数
Tuple := CoHTupleX.Create;//建立 Tuple元组变量,用于传递模型参数
Sys := CoHSystemX.Create;//建立sys系统变量,修改系统设置
Measure1 := CoHMeasureX.Create;//建立检测变量
Measure2 := CoHMeasureX.Create;//建立检测变量
//--------------
msg.Clear;
//--------------
{
OpenFramegrabber函数声明
变量Device:输入图像列表文件名,其他变量,一般采用默认参数
procedure OpenFramegrabber(Name:OleVariant; HorizontalResolution:OleVariant;
VerticalResolution:OleVariant; ImageWidth:OleVariant; ImageHeight:OleVariant;
StartRow:OleVariant; StartColumn:OleVariant; Field:OleVariant;
BitsPerChannel:OleVariant; ColorSpace:OleVariant; Generic:OleVariant;
ExternalTrigger:OleVariant; CameraType:OleVariant;
Device:OleVariant;
Port:OleVariant; LineIn:OleVariant; out AcqHandle:OleVariant);
} Framegrabber.OpenFramegrabber('File',,,,,,,'default',-,'default',
-,'default','pic/board.seq','default',,-);
msg.Lines.Add('pic from : '+'pic/board.seq');msg.Lines.Add('');
//------------- end; procedure Tmwin.FormDestroy(Sender: TObject);
begin
FreeAndNil(HXCtrl);
// Framegrabber:=nil;ShapeModel:=nil; xwin:=nil;img:=nil;box:=nil;
end; procedure Tmwin.FormShow(Sender: TObject);
begin
initData;
//-----
CreateBtn.Enabled := True;
StartBtn.Enabled := False;
end; procedure Tmwin.InitBtnClick(Sender: TObject);
begin
initData;
end; procedure Tmwin.StartBtnClick(Sender: TObject);
begin
DoMeasurement;
end; procedure Tmwin.CreateBtnClick(Sender: TObject);
begin
createShapeModel();
StartBtn.Enabled :=true;
end; end.
【《zw版·delphi与halcon系列原创教程》,网址,cnblogs.com/ziwang/】
zw版_zw中文增强版Halcon官方Delphi例程的更多相关文章
- 《zw版·delphi与halcon系列原创教程》zw版_THOperatorSetX控件函数列表 v11中文增强版
<zw版·delphi与halcon系列原创教程>zw版_THOperatorSetX控件函数列表v11中文增强版 Halcon虽然庞大,光HALCONXLib_TLB.pas文件,源码就 ...
- 点石成金:访客至上的网页设计秘笈(原书第2版) 中文PDF版
可用性设计是Web设计中最重要也是难度最大的一项任务.本书作者根据多年从业的经验,剖析用户的心理,在用户使用的模式.为扫描进行设计.导航设计.主页布局.可用性测试等方面提出了许多独特的观点,并给出了大 ...
- zw版【转发·台湾nvp系列例程】halcon与delphi系列例程
zw版[转发·台湾nvp系列例程]halcon与delphi系列例程 台湾nvp技术论坛,是目前halcon与delphi例程最多的网站,也是唯一成系列的, http://zip.nvp.com.tw ...
- 《zw版Halcon与delphi系列原创教程》发布说明
<zw版Halcon与delphi系列原创教程>发布说明 zw转载的<台湾nvp系列halcon-delphi教程>,虽然很多,不过基本上都是从cnc.数控角度的demo.. ...
- zw版·Halcon与delphi(兼谈opencv)
zw版·Halcon与delphi(兼谈opencv) QQ群 247994767(delphi与halcon) <Halcon与delphi>系列,早两年就想写,不过一方面,因为Halc ...
- 【《zw版·Halcon与delphi系列原创教程》 zw_halcon人脸识别
[<zw版·Halcon与delphi系列原创教程>zw_halcon人脸识别 经常有用户问,halcon人脸识别方面的问题. 可能是cv在人脸识别.车牌识别方面的投入太多了. 其实,人脸 ...
- 【《zw版·Halcon与delphi系列原创教程》Halcon图层与常用绘图函数
[<zw版·Halcon与delphi系列原创教程>Halcon图层与常用绘图函数 Halcon的绘图函数,与传统编程vb.c.delphi语言完全不同, 传统编程语言,甚至cad ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON DirectShow (Delphi Prism)
zw版[转发·台湾nvp系列Delphi例程]HALCON DirectShow (Delphi Prism) namespace DirectShow_Prism;interfaceuses Sys ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON HImage与Bitmap格式转换
zw版[转发·台湾nvp系列Delphi例程]HALCON HImage与Bitmap格式转换 (Delphi Prism)namespace HImage_Bitmap_Prism;interfac ...
随机推荐
- [LeetCode]题解(python):045-Jump game II
题目来源 https://leetcode.com/problems/jump-game-ii/ Given an array of non-negative integers, you are in ...
- 简单计算器--hdu1237(栈的运用)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1237 这是单纯的本题答案: #include<stdio.h> #define N 11 ...
- UIImage 调整图片大小
-(UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size { UIGraphicsBeginImageContext(size); [img d ...
- js 传参报错 参数含有数字、字母组合的字符串SyntaxError: identifier starts immediately after numeric literal
报错的意思是标识符以数字开头,这是因为js是弱类型的语言当发现第一个数字是就自动转化为数字类型的但是其中还含有字符所以报了错,‘ 报错的原因是因为我们想传的字符串,但是js却当成数字,所以需要给传的参 ...
- Spring第十篇—举例实现AOP
简述AOP AOP(Aspect-OrientedProgramming,面向方面编程),可以说是OOP(Object-Oriented Programing,面向对象编程)的补充和完善.OOP引入封 ...
- form表单中控件较多,加载完成后切换页面都很慢的解决方法
form表单中控件较多,加载完成后点击都很慢,为什么?我一页面中form表单里面上百个控件(如input.select.radio.checkbox等),还有一些js脚本,加载速度还可以,都能全部显示 ...
- 源码维护基本命令diff_patch
源码维护基本命令 diff------生成源代码补丁diff [命令行选项] 源文件 新文件-r 递归处理相应目录-N 包含新文件到patch-u 输出统一格式(unified format),这种格 ...
- RouterOS 软路由配置固定IP上网+DHCP
实现要求: 局域网所有PC机自动获取IP地址,能相互访问并且能访问外网 环境要求: 一台PC机安装两张网卡 ( 使用常用的网卡芯片,例如Intel芯片.RTL瑞昱芯片等 ) 配置说明 1.外网IP地址 ...
- 电量显示Binding Converter MVVM
用一个ProcessBar显示电量,低于20%时候,ForeGround为红色,否则为绿色, 页面使用了MVVM绑定到了ViewModel, ProcessBar XAML为 <Progress ...
- ICP算法使用遇到的问题
这几天在学习数据关联的方法,本来想使用ICP算法进行距离测距数据的配准,但是用的过程中出现问题,配的不准,而且偏差更大了. 红色的和黄色的2维激光点进行ICP配准,但将变换矩阵和黄色进行乘之后偏差更大 ...