基本信息
源码名称:halcon 找圆 函数示例源码
源码大小:0.06M
文件格式:.rar
开发语言:C#
更新时间:2018-07-13
友情提示:(无需注册或充值,赞助后即可获取资源下载链接)
嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559
本次赞助数额为: 2 元×
微信扫码支付:2 元
×
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
源码介绍
<?xml version="1.0" encoding="UTF-8"?>
<hdevelop file_version="1.0" halcon_version="10.0" cs="731527401">
<procedure name="main">
<interface/>
<body>
<c></c>
<l>dev_update_on()</l>
<c></c>
<l>read_image (Image, '4209578_094636705368_2.jpg')</l>
<c></c>
<c></c>
<c></c>
<l>disp_message (3600, '请框选出要寻找圆的外围', 'window', 12, 12, 'black', 'true')</l>
<l>draw_circle (3600, Row, Column, Radius)</l>
<l>gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)</l>
<l>disp_message (3600, '请框选出要寻找圆的内圈', 'window', 12, 12, 'black', 'true')</l>
<c></c>
<l>draw_circle (3600, Row1, Column1, Radius1)</l>
<l>gen_circle_contour_xld (ContCircle2, Row1, Column1, Radius1, 0, 6.28318, 'positive', 1)</l>
<c></c>
<l> findcircle (Image, 30, Row, Column, Radius, Radius1, 20, 1, Rowin, Colin, Radiusin)</l>
<l>disp_message (3600, '找到目标圆 ', 'window', 12, 12, 'black', 'true')</l>
<c></c>
<l>gen_circle_contour_xld (ContCircle1, Rowin, Colin, Radiusin, 0, 6.28318, 'positive', 1)</l>
<c></c>
<c></c>
<c></c>
</body>
<docu id="main">
<parameters/>
</docu>
</procedure>
<procedure name="findcircle">
<interface>
<io>
<par name="Image"/>
</io>
<ic>
<par name="PointsNumber"/>
<par name="RowBigger"/>
<par name="ColBigger"/>
<par name="RadiusBigger"/>
<par name="RadiusSmall"/>
<par name="Threshold"/>
<par name="Direction"/>
</ic>
<oc>
<par name="Rowout"/>
<par name="Colout"/>
<par name="Radiusout"/>
</oc>
</interface>
<body>
<c></c>
<c>* 函数名: findcircle</c>
<c>* 函数说明:该函数为自定义的找圆函数</c>
<c>* 该函数需要传入一个圆环,沿着圆环的径向去寻找圆周</c>
<c>* 默认的查找方向是从外环往内环去找</c>
<c></c>
<c>* time 2013-02-23</c>
<c></c>
<c>* 输入参数说明:</c>
<c>* Image: 传入的图像句柄</c>
<c>* PointsNumber: 寻边所用的点的个数,一般设置成30左右,一般来说越多越精确,但是也越慢</c>
<c>* RowBigger: 传入的圆环的圆心 y</c>
<c>* ColBigger: 传入的圆环的圆心 x</c>
<c>* RadiusBigger: 外环的半径</c>
<c>* RadiusSmall: 内环的半径</c>
<c>* Threshold: 图像的阈值,这个参数很有用,需要根据图像的效果来微调该参数</c>
<c>* Direction: 找圆的方向,0--从外向内</c>
<c>* 1--从内向外 </c>
<c></c>
<c>*输出参数说明</c>
<c>* Rowout:找到的圆周的圆心Y</c>
<c>* Colout:找到的圆周的圆心X</c>
<c>* Radiusout:找到的圆周的半径</c>
<c></c>
<c></c>
<l>dev_update_off()</l>
<l>* gen_circle_contour_xld (ContCircle, Rowoutter, Coloutter, RadiusBigger, 0, 6.28, 'positive', 4)</l>
<c></c>
<l>point_number:=PointsNumber</l>
<l>rad_step:=6.28/point_number</l>
<c></c>
<c></c>
<l>Rowoutter:=[]</l>
<l>Coloutter:=[]</l>
<l>Row_inner:=[]</l>
<l>Col_inner:=[]</l>
<c></c>
<c></c>
<c></c>
<c>*生成第1个圆的圆周点</c>
<l>for Index := 1 to point_number by 1</l>
<l> Row0 := RowBigger RadiusBigger*sin(rad_step*Index)</l>
<l> Col0 := ColBigger RadiusBigger*cos(rad_step*Index)</l>
<l> Rowoutter[Index-1]:=Row0</l>
<l> Coloutter[Index-1]:=Col0</l>
<l>endfor</l>
<c></c>
<c>*显示第1个圆的所有圆周点</c>
<l> disp_cross (3600, Rowoutter, Coloutter, 20, 1)</l>
<c></c>
<c></c>
<c>*生成第2个圆的圆周点</c>
<l>for Index := 1 to point_number by 1</l>
<l> Row0 := RowBigger RadiusSmall*sin(rad_step*Index)</l>
<l> Col0:= ColBigger RadiusSmall*cos(rad_step*Index)</l>
<l> Row_inner[Index-1]:=Row0</l>
<l> Col_inner[Index-1]:=Col0</l>
<l>endfor</l>
<c></c>
<c>*显示第2个圆的所有圆周点</c>
<l> disp_cross (3600, Row_inner, Col_inner, 20, 1)</l>
<c> </c>
<c> </c>
<c>*准备测量用的测量框所需要的信息 </c>
<l>for Index := 1 to point_number by 1</l>
<c></c>
<l> row_rect[Index-1]:=(Row_inner[Index-1] Rowoutter[Index-1])/2</l>
<l> col_rect[Index-1]:=(Col_inner[Index-1] Coloutter[Index-1])/2</l>
<l> tuple_abs (RadiusBigger-RadiusSmall, Abs)</l>
<l> tuple_gen_const (point_number, Abs/2, Len1_rect)</l>
<l> length2 :=30</l>
<l> tuple_gen_const (point_number, length2, Len2_rect)</l>
<c></c>
<l> gen_arrow_contour_xld (Arrow, Rowoutter[Index-1],Coloutter[Index-1], Row_inner[Index-1],Col_inner[Index-1], 50, 20)</l>
<c></c>
<l> if(rad_step*Index>3.1415926)</l>
<l> rad2[Index-1]:=3.1415926-rad_step*Index</l>
<l> else</l>
<l> rad2[Index-1]:=-3.1415926-rad_step*Index</l>
<l> endif</l>
<c> </c>
<l> if(Direction=1)</l>
<l> rad2[Index-1]:=3.14 rad2[Index-1]</l>
<l> endif</l>
<l>endfor</l>
<c></c>
<c></c>
<l>* stop()</l>
<c></c>
<c></c>
<c></c>
<c>*计算相对模板圆心的坐标补偿</c>
<l>row_delta:=0 </l>
<c>*Row_circle-row_std</c>
<l>col_delta:=0 </l>
<c>*Col_circle-col_std</c>
<c></c>
<l>get_image_size (Image, Width, Height)</l>
<c></c>
<l>for i:=0 to point_number-1 by 1</l>
<c> *这里生成矩形只是为了显示,对算法没有帮助</c>
<c> *注意row_delta和col_delta,这是和模板计算相对roi距离时需要的</c>
<l> gen_rectangle2_contour_xld(conu,row_rect[i] row_delta, col_rect[i] col_delta, rad2[i],Len1_rect[i], Len2_rect[i])</l>
<l> gen_measure_rectangle2 (row_rect[i] row_delta, col_rect[i] col_delta, rad2[i],Len1_rect[i], Len2_rect[i], Width, Height, 'nearest_neighbor', MeasureHandle)</l>
<l> measure_pos (Image, MeasureHandle, 12, Threshold, 'all', 'first', RowEdge, ColumnEdge, Amplitude, Distance)</l>
<c> </c>
<l> close_measure (MeasureHandle)</l>
<c></c>
<l> disp_cross (3600, RowEdge, ColumnEdge, 40, 0)</l>
<c> </c>
<l> tuple_length (RowEdge, Length)</l>
<c></c>
<c> *取不到点置为-1,待后续剔除点对</c>
<l> if(Length<1)</l>
<l> row_o[i]:=-1 </l>
<l> col_o[i]:=-1</l>
<l> else</l>
<c> *如果取到很多个点,默认取第一个点</c>
<c> *TODO:这里需要精算取到的多个点的特性,避免误取</c>
<l> row_o[i]:=RowEdge[0]</l>
<l> col_o[i]:=ColumnEdge[0]</l>
<l> endif</l>
<c> </c>
<l>endfor</l>
<c>*过滤无效的点信息</c>
<l>tuple_find(row_o,-1,indice)</l>
<l>tuple_remove(row_o,indice,row_o2)</l>
<l>tuple_remove(col_o,indice,col_o2)</l>
<c></c>
<l>gen_contour_polygon_xld (Contour, row_o2, col_o2)</l>
<l>fit_circle_contour_xld (Contour, 'geotukey', -1, 0, 0, 3, 2, RowX, ColumnX, RadiusX, StartPhi1, EndPhi1, PointOrder1)</l>
<c> </c>
<c></c>
<l>Rowout:=RowX</l>
<l>Colout:=ColumnX</l>
<l>Radiusout:=RadiusX</l>
<l>* stop()</l>
<c></c>
<c> </c>
<c></c>
<l>return ()</l>
</body>
<docu id="findcircle">
<example lang="zh_CN">read_image (Image, 'C:/Users/John/Desktop/halcon_rearcamera/12/11.bmp')
point_number:=50
disp_message (3600, '请绘大圆,寻找方向为从大圆往小圆去找', 'image', 12, 12, 'black', 'true')
draw_circle (3600, Row, Column, Radius)
gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28, 'positive', 4)
disp_message (3600, '请绘制小圆,寻找方向为从大圆往小圆去找', 'image', 12, 12, 'black', 'true')
draw_circle (3600, Row1, Column1, Radius1)
gen_circle_contour_xld (ContCircle, Row, Column, Radius1, 0, 6.28, 'positive', 4)
*自定义找圆函数
findcircle (Image, point_number, Row, Column, Radius, Radius1, 9, Rowout, Colout, Radiusout)
*圆周查找结束
dev_set_color ('green')
dev_set_line_width (3)
*取得外环的圆心坐标,并且显示出来
gen_circle_contour_xld (ContCircle, Rowout, Colout, Radiusout, 0, 6.28318, 'positive', 1)
*///////////外圆查找结束
disp_message (3600, '找到圆周,(' Rowout ',' Colout ')' ' 半径 ' Radiusout, 'image', 12, 12, 'black', 'true')
</example>
<parameters>
<parameter id="ColBigger">
<default_value>0</default_value>
<description lang="zh_CN">传入的圆环的圆心 x</description>
<sem_type>real</sem_type>
</parameter>
<parameter id="Colout">
<description lang="zh_CN">找到的圆周的圆心X</description>
<sem_type>real</sem_type>
</parameter>
<parameter id="Direction">
<default_value>0</default_value>
<description lang="zh_CN">找圆的方向,0--从外向内 1--从内向外 </description>
<sem_type>number</sem_type>
</parameter>
<parameter id="Image">
<description lang="zh_CN">传入的图像句柄</description>
<multichannel>optional</multichannel>
<sem_type>image</sem_type>
</parameter>
<parameter id="PointsNumber">
<default_value>30</default_value>
<description lang="zh_CN">寻边所用的点的个数,一般设置成30左右,一般来说越多越精确,但是也越慢</description>
<sem_type>integer</sem_type>
<type_list>
<item>integer</item>
</type_list>
</parameter>
<parameter id="RadiusBigger">
<description lang="zh_CN">外环的半径</description>
<sem_type>real</sem_type>
</parameter>
<parameter id="RadiusSmall">
<description lang="zh_CN">内环的半径</description>
<sem_type>real</sem_type>
</parameter>
<parameter id="Radiusout">
<description lang="zh_CN">找到的圆周的半径</description>
<sem_type>real</sem_type>
</parameter>
<parameter id="RowBigger">
<default_value>0</default_value>
<description lang="zh_CN">传入的圆环的圆心 y</description>
<sem_type>real</sem_type>
</parameter>
<parameter id="Rowout">
<description lang="zh_CN">找到的圆周的圆心Y</description>
<sem_type>real</sem_type>
</parameter>
<parameter id="Threshold">
<default_value>8</default_value>
<description lang="zh_CN">图像的阈值,这个参数很有用,需要根据图像的效果来微调该参数</description>
<sem_type>real</sem_type>
</parameter>
</parameters>
</docu>
</procedure>
</hdevelop>