实例介绍
【实例截图】
【核心代码】
<?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>
标签: ffdshow
相关软件
网友评论
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
支持(0) 盖楼(回复)