2021-07-28

该博客介绍了如何使用Halcon进行图像处理,包括读取模板、进行模板匹配、仿射变换、区域平移、特征区域拟合以及算子处理。通过多模板匹配找到目标,应用仿射变换和区域拟合得到精确的圆数据,最终输出圆的个数、直径和面积等信息。
摘要由CSDN通过智能技术生成

Halcon-仿射变换和拟合

利用创建的模板对目标图像进行模板匹配,然后进行仿射变换和区域平移,对提取出来的特征区域做拟合操作再进行算子处理得到自己想要的数据

以多模板为例
如下:

*NumImages :=3


read_shape_model('模板/model1.shm', ModelID1)
read_shape_model('模板/model2.shm', ModelID2)
read_region(Region, '模板/Region.tif')
*for n :=1 to NumImages by 1
dev_close_window()
read_image(Image, 'D:/image/picture1.bmp')

dev_open_window(0, 0, 512, 512, 'black', WindowHandle)

dev_display(Image) 
find_shape_model(Image, ModelID1, rad(0), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
find_shape_model(Image, ModelID2,rad(0), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row2, Column2, Angle1, Score1)
dev_display_shape_matching_results(ModelID1, 'red', Row, Column, Angle, 1, 1, 0)
dev_display_shape_matching_results(ModelID2, 'red', Row2, Column2, Angle1, 1, 1, 0)

vector_angle_to_rigid(1003.48, 1342.91, -8.18367e-006, Row2, Column2, Angle1, HomMat2D)
affine_trans_region(Region, RegionAffineTrans, HomMat2D, 'constant')



reduce_domain(Image, RegionAffineTrans, ImageReduced)

mean_sp(ImageReduced,ImageMeansp,3,3,101,201)

threshold (Image, Regions, 0, 50)


connection (Regions, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions1, 'area', 'and', 1000, 10000)
select_shape (SelectedRegions1, SelectedRegions, 'circularity', 'and', 0.5, 1)

gen_contour_region_xld (SelectedRegions, Contours, 'border')
fit_circle_contour_xld (Contours, 'algebraic', -1, 0, 0, 3, 2, Row1, Column1, Radius1, StartPhi, EndPhi, PointOrder)
gen_circle_contour_xld (ContCircle, Row1, Column1, Radius1, StartPhi, EndPhi, 'positive', 1)

count_obj(SelectedRegions, Number)
disp_message (WindowHandle, '一共'+Number+'个圆', 'window', 0, 0, 'green', 'true')

for index := 0 to (Number-1) by 1
   
 
   
   dev_set_color('green')
 
  
   i := 3*index
   
   set_tposition (WindowHandle, 50*(i+1), 0)
 
   write_string (WindowHandle, 'width:'+(2*Radius1[index]))
   
 
   set_tposition (WindowHandle, 50*(i+2), 0)
 
   write_string (WindowHandle, 'Height:'+(2*Radius1[index]))
 
   set_tposition (WindowHandle, 50*(i+3), 0)
 
   write_string (WindowHandle, 'Area:'+(3.1415926*[Radius1[index]]*[Radius1[index]]))
 
  endfor
disp_message (WindowHandle, '按下F5继续', 'window', 400, 50 ,'green', 'true')
stop()
*endfor



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值