halcon+vb检测光学玻璃元件实例.docVIP

  • 69
  • 0
  • 约2.37万字
  • 约 18页
  • 2016-03-31 发布于湖北
  • 举报
halcon+vb检测光学玻璃元件实例.doc

halcon+vb检测光学玻璃元件实例发布于:2013-08-20 10:05 自然光下的玻璃元件实图 ? 环型光源下的玻璃元件图 halcon 代码 open_framegrabber (DirectShow, 1, 1, 0, 0, 0, 0, default, 8, gray, -1, false, default, Microvision MV-1400UC Digital Camera, 0, -1, AcqHandle)? *打开摄像头 grab_image_start (AcqHandle, -1) *开始铺货图像 grab_image_async (Image, AcqHandle, -1) *捕获第一帧图像 get_image_size (Image, Width, Height) *获得图像大小 dev_open_window (0, 0, Width/6, Height/6, black, WindowHandle) *打开适合大小的窗口,应为相机是1400万像素所以图想太大窗口被我缩小了。 while (true) *无限循环 ?? ?try ?? ? grab_image_async (Image, AcqHandle, -1) *捕获一帧图像 ?? ?dev_display (Image) *显示图像 ?? ?smooth_image(Image, ImageSmooth, deriche2, 0.5) *平滑图像 ?? ?threshold (ImageSmooth, Regions,125, 255) *阈值处理 *这个 表面有些灰尘呵呵不过可以当噪点过滤掉的 area_center (Regions, Area1, Row3, Column3) *获得区域中心点 ?? ?gen_contour_region_xld(Regions, Contours, border_holes) *将阈值处理后获得的区域转换成xld ?? ?smooth_contours_xld(Contours, SmoothedContours, 5) *平滑xld ?? ?select_contours_xld (SmoothedContours, SelectedContours1, contour_length, 4000, 8000, -0.5, 0.5) *选择长度在4000到8000像素之间的xld ?? ?select_contours_xld (Contours, SelectedContours2, contour_length, 10000, 13000, -0.5, 0.5) *选择长度在10000到13000之间的xld *选择后得到的xld图形就是最长的几段xld 其余的全部过滤掉了 ?? ?segment_contours_xld (SelectedContours2, ContoursSplit, lines_ellipses, 0, 2, 2) *对方性xld进行分割 分割主要是为了去除尖刺突出的xld *选取横向角度上的多边形而尖刺突出部分就被忽略了 pi := acos(0)*2? Eps := pi*2 /7 select_contours_xld (ContoursSplit, SelectedContours3, direction, ?pi/2 + Eps, pi/2 - Eps, -0.5, 0.5) *选择横向角度的多边形 select_contours_xld (SelectedContours3, SelectedContoursFinal, length, 20, 200000, -0.5, 0.5) *选择横向角度的长度在20到200000的多边形 觉得这一部多余 ?呵呵不过是多次测试参数后才发现多余 ?之后就懒得改了。 union_collinear_contours_xld(SelectedContoursFinal, ContourTu, 150, 5, 10, 0.70, attr_keep) *联合所有备选横向方向上的xld间距在150个像素一下的 select_contours_xld (ContourTu, ContourTuFinal, length, 1500, 200000, -0.5, 0.5) *选择1500到200000像素之间的xld 这个选择主要是选出 拟合出来的玻璃元件上下边缘的直线 sort_contours_xld(ContourTuFinal, ContourTuSort, upper_left, true, row) *索引选择的xld fit_line_contour_xld(ContourTuSort,

文档评论(0)

1亿VIP精品文档

相关文档