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