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

螺丝十字槽检测

[复制链接]
XLZDHKJ 发表于 2025-7-9 19:06:00 | 显示全部楼层 |阅读模式
11.png
向大神求教,如何检出中间这颗螺丝的十字槽的缺陷
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
大凡光学,专注标定板提供
hankchang 发表于 2025-7-14 16:46:01 | 显示全部楼层
  1. dev_close_window()
  2. dev_open_window(0, 0, 512, 512, 'black', WindowHandle)
  3. read_image (Image913523B340af66e82c64f, 'image/9_13523_b340af66e82c64f.png')
  4. rgb1_to_gray(Image913523B340af66e82c64f, GrayImage)
  5. dev_display(GrayImage)
  6. gen_rectangle2(Rectangle, 714.6, 883, 0, 69.36, 9.86)
  7. gen_circle(Circle, 715.1, 881.93, 31.75)

  8. difference(Rectangle, Circle, RegionDifference)
  9. gen_contour_region_xld (RegionDifference, Contours, 'border')
  10. ***建立shape model
  11. create_shape_model_xld(Contours, 'auto', -1.57, 3.14, 'auto', 'auto', 'ignore_local_polarity', 15, ModelID)
  12. get_shape_model_contours(ModelContours, ModelID, 1)
  13. find_shape_model(GrayImage, ModelID, -1.57, 3.14, 0.5, 3, 0.5, ['least_squares','max_deformation 2'], 0, 0.1, Row2, Column2, Angle, Score)
  14. dev_update_off()
  15. for i:=0 to |Row2|-1 by 1
  16.     vector_angle_to_rigid (0, 0, 0, Row2, Column2, Angle, HomMat2D)
  17.     affine_trans_contour_xld(ModelContours, ContoursAffineTrans, HomMat2D)   
  18.     gen_region_contour_xld (ContoursAffineTrans, Region, 'filled')
  19.     union1(Region, RegionUnion)
  20.     shape_trans(RegionUnion, RegionTrans, 'rectangle2')
  21.     difference(RegionTrans, RegionUnion, RegionDifference1)
  22.     opening_circle(RegionDifference1, RegionOpening, 2.5)
  23.     dilation_rectangle1(RegionOpening, RegionDilation, 11, 25)
  24.     smallest_rectangle2(RegionUnion, Row3, Column3, Phi1, Length11, Length21)
  25.     gen_rectangle2(Rectangle1, Row3, Column3, Phi1+1.57, Length11-25, Length21)
  26.     difference(Rectangle1, RegionDilation, RegionDifference2)
  27.     erosion_circle(RegionDifference2, RegionErosion, 2.5)
  28.     connection(RegionErosion, ConnectedRegions)
  29.     count_obj(ConnectedRegions, Number)
  30.     intensity(ConnectedRegions, GrayImage, Mean, Deviation)
  31.     **用MLP 分類器會比較穩定
  32.     ***把Mean,Deviation 或是其他region等變數作為MLP輸入, 訓練MLP 即可分類結果0,1 (Pass,Fail)
  33.     **一個螺絲有兩的分類結果 任一個Fail 就是Fail
  34.     if((Mean[0]>160 and Deviation[0]>45) or(Mean[1]>160 and Deviation[1]>45))
  35.         dev_disp_text('Fail', 'image', Row2+100,Column2, 'magenta', [], [])
  36.     else
  37.         dev_disp_text('Pass', 'image', Row2+100,Column2, 'magenta', [], [])
  38.     endif
  39. endfor
复制代码
result1.jpg
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复 支持 1 反对 0

使用道具 举报

 楼主| XLZDHKJ 发表于 2025-7-15 16:15:14 | 显示全部楼层
谢谢,学习了
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
xah 发表于 2025-7-16 16:57:20 | 显示全部楼层
厉害!{:1_6:}{:1_6:}{:1_6:}{:1_6:}
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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