背景:当镜头不是远心镜头时,FA镜头没法知道一个像素的尺寸。
1、标定板信息
标定板7*7,圆的直径是1.25mm,两个圆的距离是2.5mm,求出每排两两圆心距的像素距离,然后平均值。两点的真实距离为D,像素距离为d,这时x方向像素当量 距离=D/d;同理求y方向的像素当量的距离。
2、halcon求x方向像素当量的方法
read_image (Image, 'C:/Users/tingjie_xu/Desktop/BD1.bmp')
rgb1_to_gray(Image,Cal)
*将标定板上的圆点区域抠图
threshold (Cal, Regions, 0,100)
connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions1, 'area', 'and', 3500, 5000)
fill_up (SelectedRegions1, RegionFillUp)
select_shape (RegionFillUp, SelectedRegions2, 'roundness', 'and', 0.73303, 1)
union1 (SelectedRegions2, RegionUnion)
shape_trans (RegionUnion, RegionTrans, 'convex')
inner_rectangle1 (RegionTrans, Row1, Column1, Row2, Column2)
gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
dilation_rectangle1 (Rectangle, RegionDilation, 200, 200)
reduce_domain (Cal, RegionDilation, ImageReduced)
*计算圆点所构成的区域的长和宽
threshold (ImageReduced, Regions, 0, 100)
connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions1, 'area', 'and', 3500, 5000)
fill_up (SelectedRegions1, RegionFillUp)
select_shape (RegionFillUp, SelectedRegions2, 'roundness', 'and', 0.73303, 1)
sort_region (SelectedRegions2, SortedRegions, 'character', 'true', 'row')
count_obj (SortedRegions, PointNum)
colNum:=7
RowNum:=PointNum/colNum
union1 (SortedRegions, RegionUnion)
smallest_rectangle2 (RegionUnion, Row, Column, Phi, Length1, Length2)
i:=0
for Index_I := 0 to colNum-1 by 1
for Index_J := 1 to RowNum by 1
if(Index_J+1<=RowNum)
select_obj(SortedRegions, ObjectSelected1, Index_J+Index_I*7)
select_obj(SortedRegions, ObjectSelected2, Index_J+1+Index_I*7)
gen_contour_region_xld(ObjectSelected1,Contours1, 'border')
gen_contour_region_xld(ObjectSelected2,Contours2, 'border')
*gen_contour_region_xld(ObjectSelected,Contours, 'border')
fit_circle_contour_xld (Contours1, 'algebraic', -1, 0, 0, 3, 2, Row11, Column11, Radius11, StartPhi11, EndPhi11, PointOrder11)
gen_circle_contour_xld(ContCircle1, Row11, Column11, Radius11, 0, 6.28318, 'positive', 1)
fit_circle_contour_xld (Contours2, 'algebraic', -1, 0, 0, 3, 2, Row22, Column22, Radius22, StartPhi22, EndPhi22, PointOrder22)
gen_circle_contour_xld(ContCircle2, Row22, Column22, Radius22, 0, 6.28318, 'positive', 1)
distance_pp(Row11, Column11, Row22, Column22, Distance)
if(Distance!=0)
pix[i]:=2.5/Distance
i:=i+1
endif
endif
endfor
endfor
tuple_mean( pix,Mean)
dev_display (Cal)
dev_display (RegionUnion)