天天看點

halcon 仿射變換和區域跟随1. 應用場景2. 應用示例

仿射變換和區域跟随

  • 1. 應用場景
  • 2. 應用示例

1. 應用場景

  • 當感興趣區域不容易被捕捉,但是又必須要定位它的位置的時候,可以先選擇定位其他的特征區域。我們先找到特征區域,因為這個特征區域和感興趣區域相對位置确定,我們就可以根據仿射變換矩陣找到感興趣區域了。Mark點就是這樣應用的。

2. 應用示例

halcon 仿射變換和區域跟随1. 應用場景2. 應用示例
halcon 仿射變換和區域跟随1. 應用場景2. 應用示例
dev_set_line_width (3)
dev_set_draw ('margin')

read_image (Image, '1.png')

gen_rectangle1 (ROI_0, 121.5, 226.5, 219.5, 382.5)
reduce_domain (Image, ROI_0, ImageReduced)

gen_rectangle2 (FollowRegion, 278.5, 313.5, rad(-7.12502), 56.4358, 47.0092)
area_center (ROI_0, Area, Row, Column)

create_shape_model (ImageReduced, 'auto', rad(0), rad(360), 0.0349, 'auto', 'use_polarity', 30, 10, ModelID)
get_shape_model_contours (ModelContours, ModelID, 1)


stop()
*========================加載第二張圖像==================
read_image (Image, '2.png')
find_shape_model (Image, ModelID, rad(0), rad(360), 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row1, Column1, Angle, Score)

if (|Row1|=1)
    *基于形狀的模闆比對
    vector_angle_to_rigid (0, 0, 0, Row1, Column1, Angle, HomMat2D)
    affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2D)
    
    *跟随區域仿射變換矩陣的計算
    vector_angle_to_rigid (Row, Column, 0, Row1, Column1, -Angle, HomMat2D1)
    affine_trans_region (FollowRegion, RegionAffineTrans, HomMat2D1, 'nearest_neighbor')
endif
           

繼續閱讀