代码如下:
- dev_update_off ()
- * Calibration 01: Code generated by Calibration 01
- *相机内参
- CameraParameters := ['area_scan_division',0.0349517,16.0174,2.19737e-06,2.2e-06,909.193,2007.29,2592,1944]
- *相机外参
- CameraPose := [0.00335217,-0.0315526,0.511801,12.1381,0.797679,177.005,0]
- stop ()
- list_image_files ('Images', 'default', [], ImageFiles)
- read_image (Image, 'C:/Users/WP/Desktop/相机标定图片/圆形测量3.bmp')
- change_radial_distortion_cam_par ('adaptive', CameraParameters, 0, CamParamOut)
- gen_radial_distortion_map (Map, CameraParameters, CamParamOut, 'bilinear')
- map_image (Image, Map, ImageMapped)
- *获取图片大小
- get_image_size (ImageMapped, Width, Height)
- create_metrology_model (MetrologyHandle)
- set_metrology_model_image_size (MetrologyHandle, Width, Height)
- set_metrology_model_param (MetrologyHandle, 'camera_param', CameraParameters)
- set_metrology_model_param (MetrologyHandle, 'plane_pose', CameraPose)
- Width1:=Width/5
- Height1:=Height/5
- dev_close_window ()
- dev_get_window (WindowHandle)
- *将图片转换为灰度图片
- rgb1_to_gray (ImageMapped, GrayImage)
- *1.第一步提圆形口的真实边缘
- *对图片进行动态阈值分割
- auto_threshold (GrayImage, Regions, 2)
- select_obj (Regions, DarkRegion, 1)
- *对区域进行开运算
- opening_circle (DarkRegion, RegionOpening, 3.5)
- *对区域进行闭运算
- closing_circle (RegionOpening, RegionClosing, 3.5)
- *在对开运算后的孔洞进行填充防止闭运算后还有孔洞没有被消除
- fill_up (RegionClosing, RegionFillUp)
- *对膨胀后的图片进行边缘提取 最外圈
- boundary (RegionFillUp, RegionBorder, 'outer')
- dilation_circle (RegionBorder, RegionDilation, 3.5)
- shape_trans (RegionDilation, RegionTrans, 'outer_circle')
- *求圆心中心坐标
- area_center (RegionTrans, Area, Row, Column)
- *生成用户在窗口中交互创建的圆的参数
- *draw_circle_mod:生成用户在窗口中交互创建的圆的参数要创建一个圆
- *预计圆的中心坐标Rowln和Columnln的半径为Radiusln。在创建的圆心中再次单击鼠标后,
- *您可以移动它。单击圆弧附近可以修改圆的半径。按右鼠标键可终止该过程。
- * draw_circle_mod (WindowHandle,Row, Column, 200, Row, Column, Radius)
- gen_contour_region_xld (RegionDilation, Contours, 'border')
- fit_circle_contour_xld (Contours, 'algebraic', -1, 0, 0, 3, 2, Row, Column, Radius, StartPhi, EndPhi, PointOrder)
- *gen_circle_contour_xld:创建圆或圆弧的XLD轮廓,创建一个或多个圆弧或闭合圆。圆圈由它们的中心(行,列)和它们的半径指定。
- * gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)
- gen_circle_contour_xld(ContCircle, Row, Column, 2, StartPhi, StartPhi, 'positive', 1)
- dev_display(ContCircle)
- gen_circle_contour_xld(ContCircle2, Row-Radius, Column, 2, StartPhi, StartPhi, 'positive', 1)
- dev_display(ContCircle2)
- gen_circle_contour_xld(ContCircle3, Row+Radius, Column, 2, StartPhi, StartPhi, 'positive', 1)
- dev_display(ContCircle3)
- image_points_to_world_plane (CameraParameters, CameraPose, Row-Radius, Column, 'mm', x1, y1)
- image_points_to_world_plane (CameraParameters, CameraPose, Row+Radius, Column, 'mm', x2, y2)
- distance_pp(x1, y1, x2, y2, Distance)
- *求圆心中心坐标
- * area_center (RegionDilation, Area, Row, Column)
- *把图像坐标转化为世界坐标
- * image_points_to_world_plane (CameraParameters, CameraPose, Row, Column, 'mm', X, Y)
- dev_display (ContCircle)
- dev_set_color ('green')
- *1首先创建一个计量模型
- * create_metrology_model (MetrologyHandle)
- *添加一个找圆工具
- add_metrology_object_circle_measure (MetrologyHandle, Row, Column, Radius, 25, 5, 1.2, 30, [], [], Index)
- *2将计量对象加入到计量模型中
- * add_metrology_object_generic (MetrologyHandle, 'circle', [Row, Column, Radius], 20, 5, 1, 30, [], [], Index)
- * set_metrology_object_param (MetrologyHandle, 'all', 'measure_transition', 'negative')//白到黑
- * set_metrology_object_param (MetrologyHandle, 'all', 'measure_select', 'last')//选择第一条
- *3测量,第一个参数输入的图像,第二个参数输入的句柄
- apply_metrology_model (GrayImage, MetrologyHandle)
- *4获取计量模型中测量的所有结果
- get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter)
- *5显示圆形轮廓测量范围 显示卡尺
- get_metrology_object_result_contour (Contour, MetrologyHandle,'all', 'all', 1.5)
- *6显示圆的边缘轮廓
- get_metrology_object_measures (Contours, MetrologyHandle, 'all', 'all', Row1, Column1)
- gen_cross_contour_xld (Cross, Row1, Column1, 6, 0.785398)
- *拟合成圆
- * fit_circle_contour_xld (Cross, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius, StartPhi, EndPhi, PointOrder)
- dev_display (Contour)
- stop ()
- *7清空计量模型
- clear_metrology_model (MetrologyHandle)
- dev_display (GrayImage)
- dev_display (Contour)
- message1:='CenterRow:'+ (Parameter[0]*1000)
- message2:='CenterCol:'+ (Parameter[1]*1000)
- message3:='Radious:'+ (Parameter[2]*1000*2)
- *设置字体
- set_display_font (WindowHandle, 16, 'mono', 'true', 'false')
- disp_message (WindowHandle, message1, 'window', 0, -1, 'forest green', 'false')
- disp_message (WindowHandle, message2, 'window', 20, -1, 'forest green', 'false')
- disp_message (WindowHandle, message3, 'window', 40, -1, 'forest green', 'false')
复制代码
我实际用卡尺测量是21.149mm,程序运行测量的是22.0559mm,这误差有点大,是哪里有问题求大佬们指导
|