zw版【转发·台湾nvp系列Delphi例程】HALCON union1

zw版【转发·台湾nvp系列Delphi例程】HALCON union1



unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, HALCONXLib_TLB, StdCtrls;
type
TForm1 = class(TForm)
HWindowXCtrl1: THWindowXCtrl;
HWindowXCtrl2: THWindowXCtrl;
HWindowXCtrl3: THWindowXCtrl;
HWindowXCtrl4: THWindowXCtrl;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
image0, image1 : HImageX;
Region1, Region2 : HRegionX;
RegionUnion : HRegionX;
w, h : OleVariant;
begin
image0 := CoHImageX.Create;

image0.ReadImage('pellets');
w := image0.GetImageSize(h);
HWindowXCtrl1.HalconWindow.SetPart(0, 0, h - 1, w - 1);
image0.DispObj(HWindowXCtrl1.HalconWindow);
HWindowXCtrl1.HalconWindow.SetColor('red');
HWindowXCtrl1.HalconWindow.WriteString('original');
Region1 := image0.Threshold(128, 255);
HWindowXCtrl2.HalconWindow.SetPart(0, 0, h - 1, w - 1);
Region1.DispObj(HWindowXCtrl2.HalconWindow);
HWindowXCtrl2.HalconWindow.SetColor('red');
HWindowXCtrl2.HalconWindow.WriteString('Threshold');

image1 := image0.MeanImage(3, 3);
Region2 := image0.DynThreshold(image1, 5, 'light');
HWindowXCtrl3.HalconWindow.SetPart(0, 0, h - 1, w - 1);
Region2.DispObj(HWindowXCtrl3.HalconWindow);
HWindowXCtrl3.HalconWindow.SetColor('red');
HWindowXCtrl3.HalconWindow.WriteString('DynThreshold');

RegionUnion := Region1.ConcatObj(Region2).Union1;
HWindowXCtrl4.HalconWindow.SetPart(0, 0, h - 1, w - 1);
RegionUnion.DispObj(HWindowXCtrl4.HalconWindow);
HWindowXCtrl4.HalconWindow.SetColor('red');
HWindowXCtrl4.HalconWindow.WriteString('Union1');
end;
end.

posted @ 2015-10-01 15:16  统领  阅读(688)  评论(0编辑  收藏  举报