您当前的位置: 首页 >  图像处理

Better Bench

暂无认证

  • 2浏览

    0关注

    695博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

【图像处理】halcon根据轮廓亚像素点坐标绘图并分割为直线、圆弧、椭圆段

Better Bench 发布时间:2021-11-30 12:12:07 ,浏览量:2

1 思路

(1)读取坐标文件

(2)根据坐标绘制轮廓图gen_contour_polygon_xld

(3)使用segment_contours_xld分割轮廓

(4)使用get_contour_global_attrib_xld (Contour, ‘cont_approx’, Type)获得每个分割的轮廓性质,Type==-1表示线段; Type0表示椭圆; Type1表示圆弧

2 实现

cnt1.txt中包含了像素点的坐标X和Y值,并以换行分开 【数据和代码下载】 在这里插入图片描述

*************** 第1个边框
NO:=1
* 读取坐标数据
open_file ('cnt'+NO+'.txt', 'input', FileHandle) //原始数据.txt中
fread_string (FileHandle, String1, IsEOF) 
fread_string (FileHandle, String2, IsEOF) 
tuple_split (String1, ',', row) 
tuple_split (String2, ',', col)
tuple_number (row, NumberX) 
tuple_number (col, NumberY) 

* 根据坐标产生轮廓
gen_contour_polygon_xld (Contour, NumberY, NumberX) 

* 分割轮廓
segment_contours_xld(Contour, ContoursSplit, 'lines_circles', 10, 8, 2)

* 统计分割的轮廓数量
count_obj (ContoursSplit, Number)


open_file('line_'+NO+'.txt','output',FileHandle_line)

open_file('eclipse_'+NO+'.txt','output',FileHandle_eclipse)

open_file('circle_'+NO+'.txt','output',FileHandle_cicle)

for I := 1 to Number by 1
    select_obj (ContoursSplit, Contour, I)
    get_contour_global_attrib_xld (Contour, 'cont_approx', Type)
    * -1表示线段;0表示椭圆;1表示圆弧
    if (Type = -1)
        * 计算起始坐标
        fit_line_contour_xld (Contour, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin,  RowEnd, ColEnd, Nr, Nc, Dist)
        fwrite_string (FileHandle_line,  RowEnd+','+ColEnd +','+RowBegin+','+ColBegin+'\n')
    elseif(Type =0)
        fit_circle_contour_xld (Contour, 'atukey', -1, 2, 0, 3, 2, Row, Column,  Radius, StartPhi, EndPhi, PointOrder)
        fwrite_string (FileHandle_eclipse, Row+','+Column +'\n')
    else
        fit_circle_contour_xld (Contour, 'atukey', -1, 2, 0, 3, 2, Row, Column,  Radius, StartPhi, EndPhi, PointOrder)
        fwrite_string (FileHandle_cicle, Row+','+Column +'\n')
    endif
endfor

close_file(FileHandle_line)
close_file(FileHandle_eclipse)
close_file(FileHandle_cicle)

************************ 第二个边框
* NO:=2

* open_file ('cnt'+NO+'.txt', 'input', FileHandle) //原始数据.txt中
* fread_string (FileHandle, String1, IsEOF) 
* fread_string (FileHandle, String2, IsEOF) 
* tuple_split (String1, ',', row) 
* tuple_split (String2, ',', col)
* tuple_number (row, NumberX) 
* tuple_number (col, NumberY) 

* gen_contour_polygon_xld (Contour, NumberY, NumberX) 


* segment_contours_xld(Contour, ContoursSplit, 'lines_circles', 10, 8, 2)

* count_obj (ContoursSplit, Number)


* open_file('line_'+NO+'.txt','output',FileHandle_line)

* open_file('eclipse_'+NO+'.txt','output',FileHandle_eclipse)

* open_file('circle_'+NO+'.txt','output',FileHandle_cicle)

* for I := 1 to Number by 1
*     select_obj (ContoursSplit, Contour, I)
*     get_contour_global_attrib_xld (Contour, 'cont_approx', Type)
    * -1表示线段;0表示椭圆;1表示圆弧
*     if (Type = -1)
        * 计算起始坐标
*         fit_line_contour_xld (Contour, 'tukey', -1, 0, 5, 2, RowBegin, ColBegin,  RowEnd, ColEnd, Nr, Nc, Dist)
*         fwrite_string (FileHandle_line,  RowEnd+','+ColEnd +','+RowBegin+','+ColBegin+'\n')
*     elseif(Type =0)
*         fit_circle_contour_xld (Contour, 'atukey', -1, 2, 0, 3, 2, Row, Column,  Radius, StartPhi, EndPhi, PointOrder)
*         fwrite_string (FileHandle_eclipse, Row+','+Column +'\n')
*     else
*         fit_circle_contour_xld (Contour, 'atukey', -1, 2, 0, 3, 2, Row, Column,  Radius, StartPhi, EndPhi, PointOrder)
*         fwrite_string (FileHandle_cicle, Row+','+Column +'\n')
*     endif
* endfor

* close_file(FileHandle_line)
* close_file(FileHandle_eclipse)
* close_file(FileHandle_cicle)

绘制分割效果 在这里插入图片描述

关注
打赏
1665674626
查看更多评论
立即登录/注册

微信扫码登录

0.0383s