zw版【转发·台湾nvp系列Delphi例程】HALCON SmallestRectangle1
procedure TForm1.Button1Click(Sender: TObject);
var
img : HImageX;
w, h : OleVariant;
rg : HRegionX;
r1, r2 : OleVariant;
c1, c2 : OleVariant;
begin
img := CoHImageX.Create;
img.ReadImage('die_on_chip');
w := img.GetImageSize(h);
HWindowXCtrl1.HalconWindow.SetPart(0, 0, h - 1, w - 1);
img.DispObj(HWindowXCtrl1.HalconWindow);
rg := img.Threshold(150, 255);
HWindowXCtrl2.HalconWindow.SetPart(0, 0, h - 1, w - 1);
HWindowXCtrl2.HalconWindow.SetDraw('margin');
HWindowXCtrl2.HalconWindow.SetColor('red');
img.DispObj(HWindowXCtrl2.HalconWindow);
rg.DispObj(HWindowXCtrl2.HalconWindow);
r1 := rg.SmallestRectangle1(c1, r2, c2);
rg.GenRectangle1(r1, c1, r2, c2);
HWindowXCtrl3.HalconWindow.SetPart(0, 0, h - 1, w - 1);
HWindowXCtrl3.HalconWindow.SetDraw('margin');
HWindowXCtrl3.HalconWindow.SetColor('red');
img.DispObj(HWindowXCtrl3.HalconWindow);
rg.DispObj(HWindowXCtrl3.HalconWindow);
end;