直线标定板图片:
机械吸头位置图片:
处理代码
read_image (Image, '直线标定板图片/Left201118140641772.bmp')
get_image_size (Image, Width, Height)
dev_close_window ()
dev_open_window_fit_image (Image, 0, 0, -1, -1, WindowHandle)
dev_display (Image)
* Image Acquisition 01: Code generated by Image Acquisition 01
list_files ('直线标定板图片', ['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)
gen_empty_obj (Edges)
*|ImageFiles|
for Index := 0 to |ImageFiles| - 1 by 1read_image (Image, ImageFiles[Index])edges_sub_pix (Image, ImageEdges, 'canny', 1, 10, 40)segment_contours_xld (ImageEdges, SplitEdges, 'lines_circles', 5, 4, 2)select_shape_xld (SplitEdges, SelectedEdges, 'contlength', 'and', 30, 100000)concat_obj (Edges, SelectedEdges, Edges)dev_display (Image)dev_set_colored (12)dev_display (SelectedEdges)
* wait_seconds (0.1)
endfor
stop ()radial_distortion_self_calibration (Edges, CalibrationEdges, Width, Height, 0.01, 42, 'division', 'variable', 0, CamParMultiImage)
dev_clear_window ()
dev_set_colored (12)
dev_display (CalibrationEdges)PosInImageX:=0
PosInImageY:=0
RadiusInImage:=0
*直线畸变矫正准备
change_radial_distortion_cam_par ('fixed', CamParMultiImage, 0, CamParMultiImageRect)
get_domain (Image, Domain)
create_metrology_model (MetrologyHandle)
* Image Acquisition 01: Code generated by Image Acquisition 01
list_files ('weizhi', ['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)
for Index := 0 to |ImageFiles| - 1 by 1read_image (Image, ImageFiles[Index])* 直线标定change_radial_distortion_image (Image, Domain, ImageRectified, CamParMultiImage, CamParMultiImageRect)binary_threshold (ImageRectified, Region, 'max_separability', 'dark', UsedThreshold)fill_up (Region, RegionFillUp)difference (RegionFillUp, Region, RegionDifference)fill_up (RegionDifference, RegionFillUp1)connection (RegionFillUp1, ConnectedRegions)select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70)smallest_circle (SelectedRegions, Row, Column, Radius)add_metrology_object_circle_measure (MetrologyHandle, Row, Column, Radius, Radius/10, Radius/60, 1, 90, ['measure_distance','min_score'], [Radius/30,0.2], Index1)apply_metrology_model (ImageRectified, MetrologyHandle)gen_empty_obj (Contours)get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row1, Column1)get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter)get_metrology_object_result_contour (Contour, MetrologyHandle, 'all', 'all', 1.5)dev_display (ImageRectified)dev_display (Contour)PosInImageX[Index]:=Parameter[1]PosInImageY[Index]:=Parameter[0]RadiusInImage[Index]:=Parameter[2]
endfor
stop ()MacX:=[154.394,151.394,148.394,154.394,151.394,148.394,154.394,151.394,148.394]
MacY:=[-12.367,-12.367,-12.367,-14.368,-14.368,-14.368,-16.367,-16.367,-16.367]PointImageDis:=0
PointMacDis:=0distance_pp (PosInImageY[0], PosInImageX[0], PosInImageY[1], PosInImageX[1], Distance)
PointImageDis[0]:=Distancedistance_pp (MacY[0], MacX[0], MacY[1], MacX[1], Distance)
PointMacDis[0]:=Distancedistance_pp (PosInImageY[1], PosInImageX[1], PosInImageY[2], PosInImageX[2], Distance)
PointImageDis[1]:=Distancedistance_pp (MacY[1], MacX[1], MacY[2], MacX[2], Distance)
PointMacDis[1]:=Distancedistance_pp (PosInImageY[3], PosInImageX[3], PosInImageY[4], PosInImageX[4], Distance)
PointImageDis[2]:=Distancedistance_pp (MacY[3], MacX[3], MacY[4], MacX[4], Distance)
PointMacDis[2]:=Distancedistance_pp (PosInImageY[4], PosInImageX[4], PosInImageY[5], PosInImageX[5], Distance)
PointImageDis[3]:=Distancedistance_pp (MacY[4], MacX[4], MacY[5], MacX[5], Distance)
PointMacDis[3]:=Distancepix:=PointMacDis[0]/PointImageDis[0]vector_to_hom_mat2d (PosInImageX, PosInImageY, MacX, MacY, HomMat2D)//求解变换矩阵HomMat2D
affine_trans_point_2d (HomMat2D, PosInImageX, PosInImageY, Qx, Qy)//根据模板中心坐标求取距离相机中心实际距离