实例介绍
【实例截图】
【核心代码】
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 | <? 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 t;l>dev_update_on()& l t;/l> < c ></ c > & l t;l>read_image (Image, '4209578_094636705368_2.jpg')& l t;/l> < c ></ c > < c ></ c > < c ></ c > & l t;l>disp_message (3600, '请框选出要寻找圆的外围', 'window', 12, 12, 'black', 'true')& l t;/l> & l t;l>draw_circle (3600, Row, Column, Radius)& l t;/l> & l t;l>gen_circle_contour_xld (ContCircle, Row, Column, Radius, 0, 6.28318, 'positive', 1)& l t;/l> & l t;l>disp_message (3600, '请框选出要寻找圆的内圈', 'window', 12, 12, 'black', 'true')& l t;/l> < c ></ c > & l t;l>draw_circle (3600, Row1, Column1, Radius1)& l t;/l> & l t;l>gen_circle_contour_xld (ContCircle2, Row1, Column1, Radius1, 0, 6.28318, 'positive', 1)& l t;/l> < c ></ c > & l t;l> findcircle (Image, 30, Row, Column, Radius, Radius1, 20, 1, Rowin, Colin, Radiusin)& l t;/l> & l t;l>disp_message (3600, '找到目标圆 ', 'window', 12, 12, 'black', 'true')& l t;/l> < c ></ c > & l t;l>gen_circle_contour_xld (ContCircle1, Rowin, Colin, Radiusin, 0, 6.28318, 'positive', 1)& l t;/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 t;l>dev_update_off()& l t;/l> & l t;l>* gen_circle_contour_xld (ContCircle, Rowoutter, Coloutter, RadiusBigger, 0, 6.28, 'positive', 4)& l t;/l> < c ></ c > & l t;l>point_number:=PointsNumber& l t;/l> & l t;l>rad_step:=6.28/point_number& l t;/l> < c ></ c > < c ></ c > & l t;l>Rowoutter:=[]& l t;/l> & l t;l>Coloutter:=[]& l t;/l> & l t;l>Row_inner:=[]& l t;/l> & l t;l>Col_inner:=[]& l t;/l> < c ></ c > < c ></ c > < c ></ c > < c >*生成第1个圆的圆周点</ c > & l t;l>for Index := 1 to point_number by 1& l t;/l> & l t;l> Row0 := RowBigger RadiusBigger*sin(rad_step*Index)& l t;/l> & l t;l> Col0 := ColBigger RadiusBigger*cos(rad_step*Index)& l t;/l> & l t;l> Rowoutter[Index-1]:=Row0& l t;/l> & l t;l> Coloutter[Index-1]:=Col0& l t;/l> & l t;l>endfor& l t;/l> < c ></ c > < c >*显示第1个圆的所有圆周点</ c > & l t;l> disp_cross (3600, Rowoutter, Coloutter, 20, 1)& l t;/l> < c ></ c > < c ></ c > < c >*生成第2个圆的圆周点</ c > & l t;l>for Index := 1 to point_number by 1& l t;/l> & l t;l> Row0 := RowBigger RadiusSmall*sin(rad_step*Index)& l t;/l> & l t;l> Col0:= ColBigger RadiusSmall*cos(rad_step*Index)& l t;/l> & l t;l> Row_inner[Index-1]:=Row0& l t;/l> & l t;l> Col_inner[Index-1]:=Col0& l t;/l> & l t;l>endfor& l t;/l> < c ></ c > < c >*显示第2个圆的所有圆周点</ c > & l t;l> disp_cross (3600, Row_inner, Col_inner, 20, 1)& l t;/l> < c > </ c > < c > </ c > < c >*准备测量用的测量框所需要的信息 </ c > & l t;l>for Index := 1 to point_number by 1& l t;/l> < c ></ c > & l t;l> row_rect[Index-1]:=(Row_inner[Index-1] Rowoutter[Index-1])/2& l t;/l> & l t;l> col_rect[Index-1]:=(Col_inner[Index-1] Coloutter[Index-1])/2& l t;/l> & l t;l> tuple_abs (RadiusBigger-RadiusSmall, Abs)& l t;/l> & l t;l> tuple_gen_const (point_number, Abs/2, Len1_rect)& l t;/l> & l t;l> length2 :=30& l t;/l> & l t;l> tuple_gen_const (point_number, length2, Len2_rect)& l t;/l> < c ></ c > & l t;l> gen_arrow_contour_xld (Arrow, Rowoutter[Index-1],Coloutter[Index-1], Row_inner[Index-1],Col_inner[Index-1], 50, 20)& l t;/l> < c ></ c > & l t;l> if(rad_step*Index>3.1415926)& l t;/l> & l t;l> rad2[Index-1]:=3.1415926-rad_step*Index& l t;/l> & l t;l> else& l t;/l> & l t;l> rad2[Index-1]:=-3.1415926-rad_step*Index& l t;/l> & l t;l> endif& l t;/l> < c > </ c > & l t;l> if(Direction=1)& l t;/l> & l t;l> rad2[Index-1]:=3.14 rad2[Index-1]& l t;/l> & l t;l> endif& l t;/l> & l t;l>endfor& l t;/l> < c ></ c > < c ></ c > & l t;l>* stop()& l t;/l> < c ></ c > < c ></ c > < c ></ c > < c >*计算相对模板圆心的坐标补偿</ c > & l t;l>row_delta:=0 & l t;/l> < c >*Row_circle-row_std</ c > & l t;l>col_delta:=0 & l t;/l> < c >*Col_circle-col_std</ c > < c ></ c > & l t;l>get_image_size (Image, Width, Height)& l t;/l> < c ></ c > & l t;l>for i:=0 to point_number-1 by 1& l t;/l> < c > *这里生成矩形只是为了显示,对算法没有帮助</ c > < c > *注意row_delta和col_delta,这是和模板计算相对roi距离时需要的</ c > & l t;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 t;/l> & l t;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 t;/l> & l t;l> measure_pos (Image, MeasureHandle, 12, Threshold, 'all', 'first', RowEdge, ColumnEdge, Amplitude, Distance)& l t;/l> < c > </ c > & l t;l> close_measure (MeasureHandle)& l t;/l> < c ></ c > & l t;l> disp_cross (3600, RowEdge, ColumnEdge, 40, 0)& l t;/l> < c > </ c > & l t;l> tuple_length (RowEdge, Length)& l t;/l> < c ></ c > < c > *取不到点置为-1,待后续剔除点对</ c > & l t;l> if(Length<1)& l t;/l> & l t;l> row_o[i]:=-1 & l t;/l> & l t;l> col_o[i]:=-1& l t;/l> & l t;l> else& l t;/l> < c > *如果取到很多个点,默认取第一个点</ c > < c > *TODO:这里需要精算取到的多个点的特性,避免误取</ c > & l t;l> row_o[i]:=RowEdge[0]& l t;/l> & l t;l> col_o[i]:=ColumnEdge[0]& l t;/l> & l t;l> endif& l t;/l> < c > </ c > & l t;l>endfor& l t;/l> < c >*过滤无效的点信息</ c > & l t;l>tuple_find(row_o,-1,indice)& l t;/l> & l t;l>tuple_remove(row_o,indice,row_o2)& l t;/l> & l t;l>tuple_remove(col_o,indice,col_o2)& l t;/l> < c ></ c > & l t;l>gen_contour_polygon_xld (Contour, row_o2, col_o2)& l t;/l> & l t;l>fit_circle_contour_xld (Contour, 'geotukey', -1, 0, 0, 3, 2, RowX, ColumnX, RadiusX, StartPhi1, EndPhi1, PointOrder1)& l t;/l> < c > </ c > < c ></ c > & l t;l>Rowout:=RowX& l t;/l> & l t;l>Colout:=ColumnX& l t;/l> & l t;l>Radiusout:=RadiusX& l t;/l> & l t;l>* stop()& l t;/l> < c ></ c > < c > </ c > < c ></ c > & l t;l>return ()& l t;/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) 盖楼(回复)