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

有办法将图片里的黑色区域分割成两个这样的矩形吗?

[复制链接]
luliang971212 发表于 2025-5-12 10:47:23 | 显示全部楼层 |阅读模式
有办法将图片里的黑色区域分割成两个这样的矩形吗?
微信截图_20250512103835.png
原图:
新建 BMP 图像.png
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
Mengnimei 发表于 2025-5-12 15:13:25 | 显示全部楼层
企业微信截图_20250512151214.png
  1. read_image (Image104655hbh21ifj672ujujm, 'C:/Users/GT-LAPTOP-163/Desktop/104655hbh21ifj672ujujm.png')
  2. threshold(Image104655hbh21ifj672ujujm, Region2, 0, 128)
  3. opening_circle(Region2, RegionOpening3, 50)
  4. shape_trans(RegionOpening3, RegionTrans6, 'outer_circle')
  5. difference(Region2, RegionTrans6, RegionDifference3)
  6. connection(RegionDifference3, ConnectedRegions7)
  7. shape_trans(ConnectedRegions7, RegionTrans7, 'rectangle2')
  8. orientation_region(RegionTrans7, Phi1)
  9. select_shape (RegionTrans7, SelectedRegions2, 'orientation', 'and', 0, 5)
  10. union1(SelectedRegions2, RegionUnion4)
  11. shape_trans(RegionUnion4, RegionTrans8, 'convex')
  12. intersection(RegionTrans8, Region2, RegionIntersection4)
  13. difference(Region2,RegionIntersection4, RegionDifference4)
  14. shape_trans(RegionDifference4, RegionTrans9, 'convex')
  15. difference(Region2, RegionTrans9, RegionDifference5)
  16. shape_trans(RegionDifference5, RegionTrans10, 'convex')
  17. dev_clear_window()
  18. dev_set_draw('margin')
  19. dev_display(Image104655hbh21ifj672ujujm)
  20. dev_set_color('red')
  21. dev_display(RegionTrans9)
  22. dev_set_color('green')
  23. dev_display(RegionTrans10)
  24. stop()
复制代码


奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复 支持 1 反对 0

使用道具 举报

lqr@ 发表于 2025-5-13 08:45:50 | 显示全部楼层
这个不直接用模板匹配就行了嘛?

奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
3351422122 发表于 2025-5-13 10:45:37 | 显示全部楼层
参考一楼写的,可以借鉴写一写
  1. * Image Acquisition 01: Code generated by Image Acquisition 01
  2. read_image (Image, 'C:/Users/GeLio/Desktop/1.png')
  3. threshold(Image, Region2, 0, 128)
  4. erosion_circle (Region2, RegionErosion, 50)
  5. dilation_circle (RegionErosion, RegionDilation, 65)
  6. difference (Region2, RegionDilation, RegionDifference)
  7. connection (RegionDifference, ConnectedRegions)
  8. orientation_region (ConnectedRegions, Phi)
  9. select_shape (ConnectedRegions, SelectedRegions1, 'phi', 'and', 0, 2)
  10. union1 (SelectedRegions1, RegionUnion1)
  11. select_shape (ConnectedRegions, SelectedRegions2, 'phi', 'and', -2, 0)
  12. union1 (SelectedRegions2, RegionUnion2)
  13. shape_trans (RegionUnion1, RegionTrans1, 'convex')
  14. shape_trans (RegionUnion2, RegionTrans2, 'convex')
  15. dev_set_color ('red')
  16. boundary (RegionTrans1, RegionBorder1, 'inner')

  17. boundary (RegionTrans2, RegionBorder2, 'inner')
  18. dev_display (Image)
  19. dev_display (RegionBorder1)
  20. dev_set_color ('green')
  21. dev_display (RegionBorder2)
复制代码
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
DoronXu 发表于 2025-5-13 20:37:10 | 显示全部楼层
两个方向 直接腐蚀?
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
lqr@ 发表于 2025-5-13 20:38:55 | 显示全部楼层
  1. read_image (Image, '1')
  2. rgb1_to_gray (Image, GrayImage)
  3. gen_region_line (ROI_0, 178.041, 242.57, 499.946, 699.455)
  4. gen_region_line (TMP_Region, 498.885, 700.446, 423.022, 761.91)
  5. union2 (ROI_0, TMP_Region, ROI_0)
  6. gen_region_line (TMP_Region, 123.671, 298.879, 425.073, 763.959)
  7. union2 (ROI_0, TMP_Region, ROI_0)
  8. gen_region_line (TMP_Region, 172.88, 243.561, 117.52, 298.879)
  9. union2 (ROI_0, TMP_Region, ROI_0)
  10. area_center (ROI_0, Area, Row2, Column2)
  11. reduce_domain (GrayImage, ROI_0, ImageReduced)
  12. create_shape_model (ImageReduced, 5, rad(0), rad(360), 'auto', 'auto', 'use_polarity', 2, 1, ModelID)

  13. gen_region_line (ROI_1, 400.457, 301.304, 105.938, 567.941)
  14. gen_region_line (TMP_Region, 399.29, 302.141, 457.462, 337.676)
  15. union2 (ROI_1, TMP_Region, ROI_1)
  16. gen_region_line (TMP_Region, 457.473, 336.413, 142.643, 629.135)
  17. union2 (ROI_1, TMP_Region, ROI_1)
  18. gen_region_line (TMP_Region, 105.498, 560.663, 141.44, 628.318)
  19. union2 (ROI_1, TMP_Region, ROI_1)
  20. area_center (ROI_1, Area1, Row1, Column1)
  21. reduce_domain (GrayImage, ROI_1, ImageReduced)
  22. create_shape_model (ImageReduced, 5, rad(0), rad(360), 'auto', 'auto', 'use_polarity', 2, 1, ModelID1)


  23. for Index := 0 to 360 by 1
  24. rgb1_to_gray (Image, GrayImage)
  25. rotate_image (GrayImage, GrayImage , Index, 'constant')
  26. dev_set_color ('red')
  27. find_shape_model (GrayImage, ModelID, rad(0), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
  28. vector_angle_to_rigid (Row2, Column2, 0, Row, Column, Angle, HomMat2D)
  29. affine_trans_region (ROI_0, RegionAffineTrans, HomMat2D, 'nearest_neighbor')

  30. dev_set_color ('green')
  31. find_shape_model (GrayImage, ModelID1, rad(0), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
  32. vector_angle_to_rigid (Row1, Column1, 0, Row, Column, Angle, HomMat2D)
  33. affine_trans_region (ROI_1, RegionAffineTrans1, HomMat2D, 'nearest_neighbor')
  34. stop()
  35. endfor
复制代码
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复 支持 1 反对 0

使用道具 举报

CMHCYL 发表于 2025-5-15 11:46:32 | 显示全部楼层
这个效果可以吗
屏幕截图 2025-05-15 114517.png
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
张满满 发表于 2025-5-17 19:15:03 | 显示全部楼层
下载.png
  1. read_image (Image, 'image.png')
  2. edges_color_sub_pix (Image, Edges, 'canny', 1, 20, 40)
  3. segment_contours_xld (Edges, ContoursSplit, 'lines_circles', 5, 4, 2)
  4. union_collinear_contours_ext_xld (ContoursSplit, UnionContours, 110, 1, 2, 0.1, 0, -1, 1, 1, 1, 1, 1, 0, 'attr_keep')
  5. union_adjacent_contours_xld (UnionContours, UnionContours1, 10, 1, 'attr_keep')
复制代码
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
回复 支持 3 反对 0

使用道具 举报

姜宗谷 发表于 2025-5-21 11:53:04 | 显示全部楼层
  1. read_image (Image104655hbh21ifj672ujujm, 'C:/Users/Awei/Desktop/104655hbh21ifj672ujujm.png')
  2. rgb1_to_gray(Image104655hbh21ifj672ujujm, GrayImage)

  3. threshold(GrayImage, Region, 0, 100)
  4. opening_circle(Region, RegionOpening, 50)
  5. difference(Region, RegionOpening, RegionDifference)
  6. connection(RegionDifference, ConnectedRegions)

  7. *第一个
  8. select_shape(ConnectedRegions, SelectedRegions, 'phi', 'and', -1, 0)
  9. union1(SelectedRegions, RegionUnion)
  10. shape_trans(RegionUnion, RegionTrans, 'convex')
  11. boundary(RegionTrans, BounDerOne, 'inner')

  12. *第二个
  13. select_shape(ConnectedRegions, SelectedRegions, 'phi', 'and', 0,1)
  14. union1(SelectedRegions, RegionUnion)
  15. shape_trans(RegionUnion, RegionTrans, 'convex')
  16. boundary(RegionTrans, BounDerTwo, 'inner')

  17. *显示
  18. dev_display(GrayImage)
  19. dev_display(BounDerOne)
  20. dev_display(BounDerTwo)
复制代码

1.png
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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