zw版【转发·台湾nvp系列Delphi例程】HALCON HistoToThresh1
procedure TForm1.Button1Click(Sender: TObject);
var
image0 : HImageX;
rg : HRegionX;
AbsoluteHisto, RelativeHisto : OleVariant;
op : HOperatorSetX;
MinThresh, MaxThresh : OleVariant;
w, h : OleVariant;
begin
image0 := CoHImageX.Create;
image0.ReadImage(‘clip‘);
w := image0.GetImageSize(h);
HWindowXCtrl1.HalconWindow.SetPart(0, 0, h - 1, w - 1);
image0.DispObj(HWindowXCtrl1.HalconWindow);
rg := image0.Threshold(60, 180);
HWindowXCtrl2.HalconWindow.SetPart(0, 0, h - 1, w - 1);
image0.DispObj(HWindowXCtrl2.HalconWindow);
rg.DispObj(HWindowXCtrl2.HalconWindow);
AbsoluteHisto := rg.GrayHisto(image0, RelativeHisto);
op := CoHOperatorSetX.Create;
op.HistoToThresh(AbsoluteHisto, 2, MinThresh, MaxThresh);
rg := image0.Threshold(MinThresh[0], MaxThresh[0]);
HWindowXCtrl3.HalconWindow.SetPart(0, 0, h - 1, w - 1);
image0.DispObj(HWindowXCtrl3.HalconWindow);
rg.DispObj(HWindowXCtrl3.HalconWindow);
end;