* * Image Processing with HALCON * bga-simple.dev * * bga-simple.dev - ball grid array inspection * (threshold value predefined "by hand") * * - - - - - - - - - - - - - - - - - - - - - - - - - - - - * switch off the automatic update of HDevelop (to get faster): * - - - - - - - - - - - - - - - - - - - - - - - - - - - - * read image, check its size and open appropriately sized window: read_image (Image, 'bga.tif') get_image_pointer1 (Image, _, Type, Width, Height) dev_close_window () dev_open_window (0, 0, Width*0.5, Height*0.5, 'black', WindowHandle) dev_set_part (0, 0, Height-1, Width-1) dev_display (Image) wait_seconds (1) * dev_update_window ('off') - - - - - - - - - - - - - - - - - - - - - - - - - - - - * prepare visualization: dev_set_draw ('margin') dev_set_colored (12) dev_set_line_width (1) * - - - - - - - - - - - - - - - - - - - - - - - - - - - - * detecting the balls with subpixel accuracy: threshold (Image, Region, 100, 255) connection (Region, ConnectedRegions) select_shape (ConnectedRegions, SelectedRegions, ['area','circularity'], 'and', [100,0.8], [200,1.0]) boundary (SelectedRegions, RegionBorder, 'inner') dilation_circle (RegionBorder, RegionDilation, 3.5) union1 (RegionDilation, RegionUnion) reduce_domain (Image, RegionUnion, ImageReduced) edges_sub_pix (ImageReduced, Edges, 'lanser2', 0.5, 20, 40) fit_ellipse_contour_xld (Edges, 'fitzgibbon', -1, 0, 0, 200, 3, 2, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder) gen_ellipse_contour_xld (ContEllipse, Row, Column, Phi, Radius1, Radius2, StartPhi, EndPhi, PointOrder, 1.5) dev_set_part (701, 771, 723, 793) crop_part (Image, ImagePart, 773-10, 781-10, 22, 22) dev_display (Image) dev_set_color ('red') dev_display (Edges) dev_set_color ('green') dev_display (ContEllipse)