HALCON-胶宽测量

[复制链接]
查看82476 | 回复0 | 2024-5-29 08:25:47 | 显示全部楼层 |阅读模式
思路代码分享



尺寸测量







代码:


dev_close_window ()dev_open_window (0, 0, 512, 512, 'black', WindowHandle)count_seconds (T1)read_image (Image, '0.Jpeg')decompose3 (Image, R, G, B)mean_image (R, ImageMean, 255, 255)dyn_threshold (R, ImageMean, RegionDynThresh, 35, 'dark')connection (RegionDynThresh, ConnectedRegions)select_shape_std (ConnectedRegions, SelectedRegions, 'max_area', 70)dilation_circle (SelectedRegions, RegionDilation, 3.5)skeleton (RegionDilation, Skeleton)gen_contours_skeleton_xld (Skeleton, Contours, 20, 'filter')sort_contours_xld (Contours, SortedContours, 'upper_left', 'true', 'row')count_obj (SortedContours, Number8)for Index2 := 1 to Number8 by 1length1 := Index2select_obj (SortedContours, ObjectSelected, length1)get_contour_xld (ObjectSelected, Rows, Columns)gen_cross_contour_xld (Cross, Rows, Columns, 6, 0.785398)dev_display (R)dev_display (Cross)get_image_size (ImageMean, Width, Height)gen_empty_obj (Edge_MeasureOut)gen_empty_obj (Rectangle_MeasureOut)*测量距离数组DisRet:=[]RecDis:=15for Index := 0 to |Rows|-RecDis-1 by RecDis    *生成测量卡尺,隔8个像素,计算一小段区域角度    angle_lx (Rows[[Index]], Columns[[Index]], Rows[[Index+RecDis]], Columns[[Index+RecDis]], Angle)    *把每一个卡尺轮廓画出来    gen_rectangle2_contour_xld (Rectangle, (Rows[[Index]]+Rows[[Index+RecDis]])/2, (Columns[[Index]]+Columns[[Index+RecDis]])/2, Angle-rad(90), 50, RecDis/3)    concat_obj (Rectangle_MeasureOut, Rectangle, Rectangle_MeasureOut)    *生成垂直待测区域卡尺    gen_measure_rectangle2 ((Rows[[Index]]+Rows[[Index+RecDis]])/2, (Columns[[Index]]+Columns[[Index+RecDis]])/2, Angle-rad(90), 150, RecDis/2, Width, Height, 'nearest_neighbor', MeasureHandle)    * 设置测量参数,并测量    Sigma := 1.1    Threshold := 20    Transition := 'all'    Select := 'first'    measure_pairs (R, MeasureHandle, Sigma, Threshold, Transition, Select, RowEdgeFirst, ColumnEdgeFirst, AmplitudeFirst, RowEdgeSecond, ColumnEdgeSecond, AmplitudeSecond, IntraDistance, InterDistance)    DisRet:=[DisRet,IntraDistance]     endfordev_display (R)dev_set_color ('green')dev_display (Rectangle_MeasureOut)dev_display (Edge_MeasureOut)
endfor

count_seconds (T2)RumTime := (T2 - T1) * 1000
dev_set_color ('red')

细节展示:

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?注册哦

x
您需要登录后才可以回帖 登录 | 注册哦

本版积分规则