图像处理halcon根据轮廓亚像素点坐标绘图并分割为直线圆弧椭圆段
Posted Better Bench
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了图像处理halcon根据轮廓亚像素点坐标绘图并分割为直线圆弧椭圆段相关的知识,希望对你有一定的参考价值。
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)
绘制分割效果
以上是关于图像处理halcon根据轮廓亚像素点坐标绘图并分割为直线圆弧椭圆段的主要内容,如果未能解决你的问题,请参考以下文章