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

如何把两个分割的部分合并在一起

[复制链接]
hualin0804 发表于 2019-3-19 13:55:30 | 显示全部楼层 |阅读模式
图片中,二值化后,图形被中间的黑沟分割成了两部分,怎样把两个分割的部分合并在一起,再求整体的中心点。谢谢!
44444 - Copy.jpg
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| hualin0804 发表于 2019-3-19 14:12:22 | 显示全部楼层
试了下这个简单的方法,但是得出来的边缘不平;
  1. read_image (Image2333, 'E:/halcon//test/2333.bmp')
  2. get_image_size (Image2333, Width, Height)
  3. dev_open_window (0, 0, Width/2.5, Height/2.5, 'black', WindowHandle)
  4. dev_display (Image2333)
  5. threshold (Image2333, Regions, 107, 255)
  6. opening_circle (Regions, RegionOpening, 2.5)

  7. connection(RegionOpening, ConnectedRegions)
  8. select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 19958, 50000)

  9. fill_up (SelectedRegions, RegionFillUp)
  10. smallest_rectangle1 (RegionFillUp, Row1, Column1, Row2, Column2)

  11. gen_rectangle1 (Rectangle, Row1, Column1, Row2, Column2)
  12. dev_display (Rectangle)
  13. connection (Rectangle, ConnectedRegions1)
  14. union1 (ConnectedRegions1, RegionUnion)

  15. connection (RegionUnion, ConnectedRegions2)
复制代码
Untitled.jpg
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
绝地武士 发表于 2019-3-19 15:33:17 | 显示全部楼层
可以通过 blob初步定位,然后使用卡尺工具对四条边进行边缘提取,然后再拟合成矩形,提取中心,精度也会高很多!
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| hualin0804 发表于 2019-3-19 17:59:28 | 显示全部楼层
感谢!

我能定位出来,不知道卡尺咋用,能进一步提示一下么?
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
 楼主| hualin0804 发表于 2019-3-20 18:18:46 | 显示全部楼层
本帖最后由 hualin0804 于 2019-3-20 18:20 编辑

read_image (Image, 'E:/halcon/211/test/44444.bmp')
*
* Matching 01: Build the ROI from basic regions
gen_rectangle1 (ModelRegion, 1168.02, 1279.93, 1467.54, 1746.86)

gen_rectangle1 (ROI_0, 1165.73, 1245.19, 1464.78, 1736.18)

*
* Matching 01: Reduce the model template
reduce_domain (Image, ModelRegion, TemplateImage)
*
* Matching 01: Create the correlation model
create_ncc_model (TemplateImage, 'auto', rad(0), rad(360), 'auto', 'use_polarity', ModelID)
*
* Matching 01: Get the reference position
area_center (ModelRegion, ModelRegionArea, RefRow, RefColumn)
*
* Matching 01: Display the model region
dev_display (Image)
dev_set_color ('green')
dev_set_draw ('margin')
dev_display (ModelRegion)
gen_cross_contour_xld (TransContours, RefRow, RefColumn, 20, 0.0)
dev_display (TransContours)
stop ()
*
* Matching 01: END of generated code for model initialization
* Matching 01:  * * * * * * * * * * * * * * * * * * * * * * *
* Matching 01: BEGIN of generated code for model application
*
* Matching 01: Loop over all specified test images
TestImages := ['E:/halcon/211/test/1111.bmp','E:/halcon/211/test/222.bmp','E:/halcon/211/test/2333.bmp','E:/halcon/211/test/44444 - Copy.bmp','E:/halcon/211/test/44444.bmp']
for T := 0 to 4 by 1
    *
    * Matching 01: Obtain the test image
    read_image (Image, TestImages[T])
    *
    * Matching 01: Find the model
    find_ncc_model (Image, ModelID, rad(0), rad(360), 0.8, 0, 0.5, 'true', 0, Row, Column, Angle, Score)
    *
    * Matching 01: Display the centers of the matches in the detected positions
    dev_display (Image)
    for I := 0 to |Score| - 1 by 1
        * Matching 01: Display the center of the match
        dev_set_color ('green')
        gen_cross_contour_xld (TransContours, Row[I], Column[I], 20, Angle)
        dev_set_color ('green')
        dev_display (TransContours)
        hom_mat2d_identity (AlignmentHomMat2D)
        hom_mat2d_translate (AlignmentHomMat2D, -RefRow, -RefColumn, AlignmentHomMat2D)
        hom_mat2d_rotate (AlignmentHomMat2D, Angle[I], 0, 0, AlignmentHomMat2D)
        hom_mat2d_translate (AlignmentHomMat2D, Row[I], Column[I], AlignmentHomMat2D)
        * Matching 01: Display the aligned model region
        affine_trans_region (ModelRegion, RegionAffineTrans, AlignmentHomMat2D, 'nearest_neighbor')
        dev_display (RegionAffineTrans)
        
        dev_set_color ('red')
        gen_cross_contour_xld (TransContours, Row3[I], Column3[I], 20, Angle)
        
        gen_rectangle2 (Rectangle1, Row[I], Column[I], Angle[I], 220, 160)
        
        reduce_domain (Image, Rectangle1, ImageReduced)
        
        threshold (ImageReduced, Regions1, 53, 255)
        
        connection (Regions1, ConnectedRegions3)
        
        select_shape (ConnectedRegions3, SelectedRegions1, 'height', 'and', 100.35, 1500)

        fill_up (SelectedRegions1, RegionFillUp1)
        union1 (RegionFillUp1, RegionUnion1)
        *去除边缘一个大的凸起部分
        closing_rectangle1 (RegionUnion1, RegionClosing1, 10, 50)
        closing_circle(RegionClosing1, RegionClosing2, 28.5)
        opening_circle(RegionClosing2, RegionOpening, 3.5)
        connection (RegionOpening, ConnectedRegions4)
        
        select_shape (ConnectedRegions4, SelectedRegions2, 'area', 'and', 19846, 100000)
        shape_trans (SelectedRegions2, RegionTrans1, 'rectangle1')
        
        area_center (RegionTrans1, Area1, Row4, Column4)
        
        gen_cross_contour_xld (TransContours, Row4, Column4, 40, Angle)
        
        dev_set_color ('green')
        
        gen_cross_contour_xld (TransContours, Row4-130, Column4-92, 20, Angle)
        stop ()
    endfor
endfor
*
* Matching 01: Clear model when done
stop ()
clear_ncc_model (ModelID)
奖励计划已经开启,本站鼓励作者发布最擅长的技术内容和资源,流量变现就在现在,[点我]加入吧~~~Go
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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