使用模板匹配定位和Blob定位进行仿射变换

使用模板匹配定位和Blob定位进行仿射变换

*******************************
* 一 图像不变,平移ROI
* 几何模板匹配定位
*******************************
dev_set_draw('margin')
* 读取图像
read_image (Image, './图片/1.bmp')
* ROI区域
gen_rectangle1(Rectangle, 848, 237, 1001, 941)
* 模板区域
gen_circle(Circle, 544, 564, 241)
* 获取区域图像
reduce_domain(Image, Circle, ImageReduced)
* 创建模板
create_shape_model(ImageReduced, 'auto', 0, 0, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
* 获取模板(显示模板)
get_shape_model_contours(ModelContours, ModelID, 1)

* 获取所哟图像
list_files ('./图片', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
    * 读取图像
    read_image (Image, ImageFiles[Index])
    * 模板匹配
    find_shape_model(Image, ModelID, 0, 0, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row3, Column3, Angle, Score)
    * 匹配成功
    if(|Score|>0)
        dev_display_shape_matching_results(ModelID, 'red', Row3, Column3, Angle, 1, 1, 0)
       *ROI跟随
       area_center(Circle, Area, Row4, Column4)
       * 模板图像到当前图像的仿射变换矩阵(重点)
        vector_angle_to_rigid(Row4, Column4, 0, Row3, Column3, 0, HomMat2D)
        * 对ROI区域进行仿射变换
        affine_trans_region(Rectangle, RegionAffineTrans, HomMat2D, 'false')
        
        
    endif
    
    stop()
    
endfor


*******************************
* 二 图像不变,平移ROI
* Blob定位
*******************************
* 读取图像
read_image (Image, './图片/1.bmp')
* 阈值分割
threshold(Image, Region, 200, 255)
* 连通
connection(Region, ConnectedRegions)
*填充
fill_up(ConnectedRegions, RegionFillUp)
* 根据圆度和外接圆半径进行特征区域选择
select_shape (RegionFillUp, SelectedRegions, ['circularity','outer_radius'], 'and', [0.7,150], [1,250])
* 获取区域的中心点
area_center(SelectedRegions, Area1, Row0, Column0)
gen_cross_contour_xld(Cross, Row0, Column0, 30, Angle)

* Code generated by Image Acquisition 01
list_files ('./图片', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
    read_image (Image, ImageFiles[Index])
    * Do something threshold(Image, Region, 200, 255)
   threshold(Image, Region, 220, 255)
   connection(Region, ConnectedRegions)
    fill_up(ConnectedRegions, RegionFillUp)
   dev_display(Image)
   select_shape (RegionFillUp, SelectedRegions, ['circularity','outer_radius'], 'and', [0.7,150], [1,250])
    area_center(SelectedRegions, Area1, Row1, Column1)
    gen_cross_contour_xld(Cross, Row1, Column1, 30, Angle)
    if(|Row1|>0)
      
     
        vector_angle_to_rigid(Row0, Column0, 0, Row1, Column1, 0, HomMat2D)
        affine_trans_region(Rectangle, RegionAffineTrans, HomMat2D, 'false')
        
        
    endif
    
    stop()
    
endfor


*******************************
* 三 ROI不变,平移图像
* 几何模板匹配定位
*******************************


dev_set_draw('margin')
read_image (Image, './图片/1.bmp')
* draw_rectangle1(3600, Row1, Column1, Row2, Column2)
gen_rectangle1(Rectangle, 848, 237, 1001, 941)
* draw_circle(3600, Row, Column, Radius)
gen_circle(Circle, 544, 564, 241)
reduce_domain(Image, Circle, ImageReduced)
create_shape_model(ImageReduced, 'auto', 0, 0, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
get_shape_model_contours(ModelContours, ModelID, 1)

* Code generated by Image Acquisition 01
list_files ('./图片', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
    read_image (Image, ImageFiles[Index])
    * 模板匹配
    find_shape_model(Image, ModelID, 0, 0, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row3, Column3, Angle, Score)
    if(|Score|>0)
        dev_display_shape_matching_results(ModelID, 'red', Row3, Column3, Angle, 1, 1, 0)
       *ROI跟随
       area_center(Circle, Area, Row4, Column4)
       
        vector_angle_to_rigid( Row3, Column3, 0,Row4, Column4, 0, HomMat2D)
       affine_trans_image(Image, ImageAffinTrans, HomMat2D, 'constant', 'false')
        dev_display(Rectangle)
        
    endif
    
    stop()
    
endfor


*******************************
* 四 ROI不变,平移图像
* Blob定位
*******************************


read_image (Image, './图片/1.bmp')
threshold(Image, Region, 200, 255)
connection(Region, ConnectedRegions)
fill_up(ConnectedRegions, RegionFillUp)
select_shape (RegionFillUp, SelectedRegions, ['circularity','outer_radius'], 'and', [0.7,150], [1,250])
area_center(SelectedRegions, Area1, Row0, Column0)
gen_cross_contour_xld(Cross, Row0, Column0, 30, Angle)

* 获取所有图像
list_files ('./图片', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
    read_image (Image, ImageFiles[Index])
    * 阈值分割
   threshold(Image, Region, 220, 255)
   connection(Region, ConnectedRegions)
    fill_up(ConnectedRegions, RegionFillUp)
   dev_display(Image)
   select_shape (RegionFillUp, SelectedRegions, ['circularity','outer_radius'], 'and', [0.7,150], [1,250])
    area_center(SelectedRegions, Area1, Row1, Column1)
    gen_cross_contour_xld(Cross, Row1, Column1, 30, Angle)
    if(|Row1|>0)
      
     
        vector_angle_to_rigid( Row1, Column1,0,Row0, Column0,  0, HomMat2D)
       affine_trans_image(Image, ImageAffinTrans, HomMat2D, 'constant', 'false')
        dev_display(Rectangle)
        
    endif
    
    stop()
    
endfor


在这里插入图片描述

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值