zw版【转发·台湾nvp系列Delphi例程】HALCON max_connection
zw版【转发·台湾nvp系列Delphi例程】HALCON max_connection
procedure TForm1.Button1Click(Sender: TObject);
var
ho_Image : HImageX;
sys : HSystemX;
ho_Region : HRegionX;
hv_Information : OleVariant;
ho_ConnectedRegions, ho_ConnectedRegionsMax : HRegionX;
hv_NumConnected, hv_NumConnectedMax : Longint;
w, h : OleVariant;
begin
ho_Image := CoHImageX.Create;
ho_Image.ReadImage('monkey');
w := ho_Image.GetImageSize(h);
HWindowXCtrl1.HalconWindow.SetPart(0, 0, h - 1, w - 1);
ho_Image.DispObj(HWindowXCtrl1.HalconWindow);
sys := CoHSystemX.Create;
hv_Information := sys.GetSystem('max_connection');
ho_Region := ho_Image.Threshold(128, 255);
HWindowXCtrl2.HalconWindow.SetPart(0, 0, h - 1, w - 1);
ho_Region.DispObj(HWindowXCtrl2.HalconWindow);
sys.SetSystem('max_connection', 0);
ho_ConnectedRegions := ho_Region.Connection;
hv_NumConnected := ho_ConnectedRegions.CountObj;
HWindowXCtrl3.HalconWindow.SetColored(12);
HWindowXCtrl3.HalconWindow.SetPart(0, 0, h - 1, w - 1);
ho_ConnectedRegions.DispObj(HWindowXCtrl3.HalconWindow);
set_display_font(HWindowXCtrl3.HalconWindow.HalconID, 16, 'mono', 'true', 'false');
disp_message(HWindowXCtrl3.HalconWindow.HalconID, VarToStr(hv_NumConnected), 'window', 10, 10, 'black', 'true');
sys.SetSystem('max_connection', 1000);
ho_ConnectedRegionsMax := ho_Region.Connection;
hv_NumConnectedMax := ho_ConnectedRegionsMax.CountObj;
HWindowXCtrl4.HalconWindow.SetColored(12);
HWindowXCtrl4.HalconWindow.SetPart(0, 0, h - 1, w - 1);
ho_ConnectedRegionsMax.DispObj(HWindowXCtrl4.HalconWindow);
set_display_font(HWindowXCtrl4.HalconWindow.HalconID, 16, 'mono', 'true', 'false');
disp_message(HWindowXCtrl4.HalconWindow.HalconID, VarToStr(hv_NumConnectedMax), 'window', 10, 10, 'black', 'true');
sys.SetSystem('max_connection', hv_Information);
end;