其他分享
首页 > 其他分享> > halcon简易标定代码

halcon简易标定代码

作者:互联网

read_image (Image, 'C:/Users/HJ/Desktop/demo1/4.bmp')
threshold(Image, Region, 110, 255)
closing_circle(Region, RegionClosing, 13.5)
fill_up(RegionClosing, RegionFillUp)
connection(RegionFillUp, ConnectedRegions)
select_shape(ConnectedRegions, SelectedRegions, 'area', 'and', 15000, 9999999)
opening_circle(SelectedRegions, RegionOpening, 13.5)
orientation_region(RegionOpening, Phi)
area_center(RegionOpening, Area, Row, Column)
area_center(RegionOpening, Area, Row, Column)
if ((1.57<Phi and Phi<3.142) or (-3.142<Phi and Phi<-1.57))
    vector_angle_to_rigid(Row, Column, Phi, Row, Column, 3.14, HomMat2D)
else
    vector_angle_to_rigid(Row, Column, Phi, Row, Column, 0, HomMat2D)
endif
affine_trans_image(Image, ImageAffineTrans, HomMat2D, 'constant', 'false')
gen_rectangle2(Rectangle, Row, Column, 0, 1250, 550)
affine_trans_region(RegionOpening, RegionOpening, HomMat2D, 'nearest_neighbor')
* orientation_region (RegionOpening, PhiRef)
* PhiRef := rad(180)+PhiRef
area_center (RegionOpening, Area2, RowRef, ColumnRef)
*根据一张标准图片获得RowRef, ColumnRef


* Image Acquisition 02: Code generated by Image Acquisition 02
list_files ('C:/Users/HJ/Desktop/demo1', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
Width := 2500
Height := 1100
for Index := 0 to |ImageFiles| - 1 by 1
    read_image (Image2, ImageFiles[Index])
    * Image Acquisition 02: Do something
    threshold(Image2, Region_Each, 110, 255)
    closing_circle(Region_Each, RegionClosing_Each, 13.5)
    fill_up(RegionClosing_Each, RegionFillUp_Each)
    connection(RegionFillUp_Each, ConnectedRegions_Each)
    select_shape(ConnectedRegions_Each, SelectedRegions_Each, 'area', 'and', 15000, 9999999)
    orientation_region(SelectedRegions_Each, Phi_Each)
    area_center(SelectedRegions_Each, Area_Each, Row_Each, Column_Each)
    if ((1.57<Phi_Each and Phi_Each<3.142) or (-3.142<Phi_Each and Phi_Each<-1.57))
        vector_angle_to_rigid(Row_Each, Column_Each, Phi_Each, RowRef, ColumnRef, 3.14, HomMat2D1)
    else
        vector_angle_to_rigid(Row_Each, Column_Each, Phi_Each, RowRef, ColumnRef, 0, HomMat2D1)
    endif
    
    affine_trans_image(Image2, ImageAffineTrans_Each, HomMat2D1, 'constant', 'false')
    threshold(ImageAffineTrans_Each, Region_Out, 110, 255)
    closing_circle(Region_Out, RegionClosing_Out, 13.5)
    fill_up(RegionClosing_Out, RegionFillUp_Out)
    connection(RegionFillUp_Out, ConnectedRegions_Out)
    select_shape(ConnectedRegions_Out, SelectedRegions_Outs, 'area', 'and', 15000, 9999999)
    area_center(SelectedRegions_Outs, Area_Out, Row_Out, Column_Out)
    crop_part(ImageAffineTrans_Each, ImagePart, Row_Out-Height/2, Column_Out-Width/2, Width, Height)
endfor

 

标签:area,Area,标定,halcon,简易,SelectedRegions,RegionOpening,13.5,ConnectedRegions
来源: https://www.cnblogs.com/mr2504/p/16435092.html