设置首页收藏本站
开启左侧

求助大佬,测量线宽

[复制链接]
wjjun 发表于 2024-3-30 09:17:27 | 显示全部楼层 |阅读模式
有没有办法精准的确定,只需要外面的两条线。
捕获2.PNG 捕获3.PNG
test.png

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
风景你好 发表于 2024-3-30 14:43:08 | 显示全部楼层
这种可以吗

1711780852281.png

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| wjjun 发表于 2024-3-30 15:56:09 | 显示全部楼层

是的,我处理后都是有四条线,然后使用排序,但也不能准确找到这两个线,大佬是怎么做到的呀。
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
风景你好 发表于 2024-3-30 23:57:49 | 显示全部楼层
本帖最后由 风景你好 于 2024-3-31 00:20 编辑

wjjun 发表于 2024-3-30 15:56
是的,我处理后都是有四条线,然后使用排序,但也不能准确找到这两个线,大佬是怎么做到的呀。 ...

  1. read_image (Image, '091207lik8io3mik2s28k4.png')
  2. decompose3 (Image, Image1, Image2, Image3)

  3. * Measure 01: Code generated by Measure 01
  4. * Measure 01: Prepare measurement
  5. AmplitudeThreshold := 9
  6. RoiWidthLen2 := 80
  7. set_system ('int_zooming', 'true')
  8. * Measure 01: Coordinates for line Measure 01 [0]
  9. LineRowStart_Measure_01_0 := 250
  10. LineColumnStart_Measure_01_0 := 210
  11. LineRowEnd_Measure_01_0 := 50
  12. LineColumnEnd_Measure_01_0 := 400

  13. * Measure 01: Convert coordinates to rectangle2 type
  14. TmpCtrl_Row := 0.5*(LineRowStart_Measure_01_0+LineRowEnd_Measure_01_0)
  15. TmpCtrl_Column := 0.5*(LineColumnStart_Measure_01_0+LineColumnEnd_Measure_01_0)
  16. TmpCtrl_Dr := LineRowStart_Measure_01_0-LineRowEnd_Measure_01_0
  17. TmpCtrl_Dc := LineColumnEnd_Measure_01_0-LineColumnStart_Measure_01_0
  18. TmpCtrl_Phi := atan2(TmpCtrl_Dr, TmpCtrl_Dc)
  19. TmpCtrl_Len1 := 0.5*sqrt(TmpCtrl_Dr*TmpCtrl_Dr + TmpCtrl_Dc*TmpCtrl_Dc)
  20. TmpCtrl_Len2 := RoiWidthLen2
  21. * Measure 01: Create measure for line Measure 01 [0]
  22. * Measure 01: Attention: This assumes all images have the same size!
  23. gen_measure_rectangle2 (TmpCtrl_Row, TmpCtrl_Column, TmpCtrl_Phi, TmpCtrl_Len1, TmpCtrl_Len2, 587, 320, 'nearest_neighbor', MsrHandle_Measure_01_0)
  24. * Measure 01: ***************************************************************
  25. * Measure 01: * The code which follows is to be executed once / measurement *
  26. * Measure 01: ***************************************************************
  27. * Measure 01: The image is assumed to be made available in the
  28. * Measure 01: variable last displayed in the graphics window
  29. * copy_obj (Image2, Image, 1, 1)
  30. * Measure 01: Execute measurements
  31. measure_pos (Image2, MsrHandle_Measure_01_0, 8, AmplitudeThreshold, 'all', 'first', Row_Measure_01_0, Column_Measure_01_0, Amplitude_Measure_01_0, Distance_Measure_01_0)
  32. measure_pos (Image2, MsrHandle_Measure_01_0, 8, AmplitudeThreshold, 'all', 'last', Row_Measure_01_1, Column_Measure_01_1, Amplitude_Measure_01_0, Distance_Measure_01_0)

  33. * Measure 01: Do something with the results

  34. angle_lx (LineRowStart_Measure_01_0, LineColumnStart_Measure_01_0, LineRowEnd_Measure_01_0, LineColumnEnd_Measure_01_0, Phi)

  35. hom_mat2d_identity (HomMat2DIdentity)
  36. hom_mat2d_rotate (HomMat2DIdentity,Phi,Row_Measure_01_0, Column_Measure_01_0, HomMat2DRotate1)
  37. affine_trans_pixel (HomMat2DRotate1,Row_Measure_01_0+RoiWidthLen2,  Column_Measure_01_0, RowTrans11, ColTrans11)
  38. affine_trans_pixel (HomMat2DRotate1,Row_Measure_01_0-RoiWidthLen2,  Column_Measure_01_0, RowTrans12, ColTrans12)

  39. hom_mat2d_rotate (HomMat2DIdentity, Phi,Row_Measure_01_1, Column_Measure_01_1, HomMat2DRotate2)
  40. affine_trans_pixel (HomMat2DRotate2,Row_Measure_01_1+RoiWidthLen2,  Column_Measure_01_1, RowTrans21, ColTrans21)
  41. affine_trans_pixel (HomMat2DRotate2,Row_Measure_01_1-RoiWidthLen2,  Column_Measure_01_1, RowTrans22, ColTrans22)

  42. dev_display (Image)
  43. dev_set_line_width (5)

  44. dev_set_color ('cyan')
  45. gen_arrow_contour_xld (Arrow, LineRowStart_Measure_01_0, LineColumnStart_Measure_01_0, LineRowEnd_Measure_01_0, LineColumnEnd_Measure_01_0, 15, 15)
  46. dev_set_color ('green')
  47. gen_contour_polygon_xld (Contour1, [RowTrans11,RowTrans12], [ColTrans11,ColTrans12])
  48. gen_contour_polygon_xld (Contour2, [RowTrans21,RowTrans22], [ColTrans21,ColTrans22])

  49. line_position (Row_Measure_01_0, Column_Measure_01_0, Row_Measure_01_1, Column_Measure_01_1, RowCenter, ColCenter, Length, Phi)
  50. dev_get_window (WindowHandle)
  51. disp_message (WindowHandle, '线宽:' + Length + ' pixel', 'image', RowCenter, ColCenter, 'black', 'true')
复制代码


奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| wjjun 发表于 2024-4-1 09:37:42 | 显示全部楼层

谢谢大佬,大佬牛呀,膜拜大佬。
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
会林2022 发表于 2024-4-1 10:24:46 | 显示全部楼层
我觉得你这种最好不要用一维测量(只能测量两个点之间的距离),最好的的办法分别拟合两条直线,然后求两条直线的距离,稍微在现场的视觉工程都是这样做的

微信图片_20240401102143.png

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| wjjun 发表于 2024-4-1 11:21:18 | 显示全部楼层
会林2022 发表于 2024-4-1 10:24
我觉得你这种最好不要用一维测量(只能测量两个点之间的距离),最好的的办法分别拟合两条直线,然后求两条直 ...

是的,我使用的时edge_sub_fix来找边缘,做到很好也是找到四条线的轮廓点,然后对共线的轮廓点做并线处理,对四条线的轮廓点进行排序,对其进行距离计算,但是在排序时有时和自己想要的顺序不一样,就导致最后结果不准确,有时候准有时候不准。
  1. edges_sub_pix (ImageReduced, Edges, 'sobel', 1, 5, 20)
  2. segment_contours_xld (Edges, ContoursSplit, 'lines', 5, 4, 2)

  3. select_contours_xld (ContoursSplit, SelectedContours, 'contour_length', 20, 99999, -0.5, 0.5)

  4. union_collinear_contours_xld (SelectedContours, UnionContours, 200, 1, 200, 0.7, 'attr_keep')

  5. count_obj (UnionContours, Number)
  6. sort_contours_xld (UnionContours, SortedContours, 'upper_left', 'true', 'row')
  7. select_obj (SortedContours, ContourLine1, 1)
  8. select_obj (SortedContours, ContourLine2, 2)
  9. select_obj (SortedContours, ContourLine3, 3)
  10. select_obj (SortedContours, ContourLine4, 4)


  11. fit_line_contour_xld (ContourLine1, 'tukey', -1, 0, 5, 2, RowBegin1, ColBegin1, RowEnd1, ColEnd1, Nr, Nc, Dist)
  12. gen_contour_polygon_xld (line1, [RowBegin1, RowEnd1],[ColBegin1, ColEnd1])

  13. fit_line_contour_xld (ContourLine2, 'tukey', -1, 0, 5, 2, RowBegin2, ColBegin2, RowEnd2, ColEnd2, Nr, Nc, Dist)
  14. gen_contour_polygon_xld (line2, [RowBegin2, RowEnd2],[ColBegin2, ColEnd2])

  15. fit_line_contour_xld (ContourLine3, 'tukey', -1, 0, 5, 2, RowBegin3, ColBegin3, RowEnd3, ColEnd3, Nr, Nc, Dist)
  16. gen_contour_polygon_xld (line3, [RowBegin3, RowEnd3],[ColBegin3, ColEnd3])

  17. fit_line_contour_xld (ContourLine4, 'tukey', -1, 0, 5, 2, RowBegin4, ColBegin4, RowEnd4, ColEnd4, Nr, Nc, Dist)
  18. gen_contour_polygon_xld (line4, [RowBegin4, RowEnd4],[ColBegin4, ColEnd4])


  19. distance_contours_xld (ContourLine2, ContourLine3, ContourOut1, 'point_to_segment')
  20. get_contour_attrib_xld (ContourOut1, 'distance', Distance1)

  21. distance_contours_xld (ContourLine1, ContourLine4, ContourOut2, 'point_to_segment')
  22. get_contour_attrib_xld (ContourOut2, 'distance', Distance2)

  23. D1:=mean(Distance1)
  24. D2:=mean(Distance2)
复制代码
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
会林2022 发表于 2024-4-1 11:55:44 | 显示全部楼层
本帖最后由 会林2022 于 2024-4-1 11:59 编辑
wjjun 发表于 2024-4-1 11:21
是的,我使用的时edge_sub_fix来找边缘,做到很好也是找到四条线的轮廓点,然后对共线的轮廓点做并线处理 ...

你可以看下halcon的二维测量案例apply_metrology_model_diamond,个人慎重建议不要用xld分析来拟合直线

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
wenbo_bob 发表于 2024-4-3 09:54:13 | 显示全部楼层
学习一下
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
鑫旺兴 发表于 2024-4-4 12:39:46 | 显示全部楼层
还没学过测量的小白路过
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表