read_image (Image001, '001.bmp')
rgb1_to_gray (Image001, GrayImage)
threshold (GrayImage, Region, 100, 255)
paint_region (Region, GrayImage, ImageResult, 255, 'fill')
*
* Matching 01: ************************************************
* Matching 01: BEGIN of generated code for model initialization
* Matching 01: ************************************************
set_system ('border_shape_models', 'false')
*
* Matching 01: Obtain the model image
* Matching 01: The image is assumed to be made available in the
* Matching 01: variable last displayed in the graphics window
copy_obj (ImageResult, Image, 1, 1)
*
* Matching 01: Build the ROI from basic regions
gen_region_runs (ModelRegion, [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], [336,332,330,329,328,327,326,326,326,325,325,325,325,325,325,325,325,326,327,327,328,328,329,330,330,332,333,334,336,337,338,340,341,343,344,345,347,348,349,351,354,356,358,360,363], [342,344,348,352,354,359,361,363,365,366,368,369,371,373,374,375,376,377,377,377,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,378,377,377,377,376,374,372])
*
* Matching 01: Reduce the model template
reduce_domain (Image, ModelRegion, TemplateImage)
*
* Matching 01: Create the shape model
create_shape_model (TemplateImage, 1, rad(0), rad(360), 'auto', 'none', 'use_polarity', [9,16,3], 9, ModelID)
*
* Matching 01: Get the model contour for transforming it later into the image
get_shape_model_contours (ModelContours, ModelID, 1)
*
* Matching 01: Get the reference position
area_center (ModelRegion, ModelRegionArea, RefRow, RefColumn)
vector_angle_to_rigid (0, 0, 0, RefRow, RefColumn, 0, HomMat2D)
affine_trans_contour_xld (ModelContours, TransContours, HomMat2D)
*
* Matching 01: Display the model contours
dev_display (Image)
dev_set_color ('green')
dev_set_draw ('margin')
dev_display (ModelRegion)
dev_display (TransContours)
stop ()
*
* Matching 01: END of generated code for model initialization
* Matching 01: * * * * * * * * * * * * * * * * * * * * * * *
* Matching 01: BEGIN of generated code for model application
* Matching 01: The following operations are usually moved into
* Matching 01: that loop where the acquired images are processed
*
* Matching 01: Find the model
find_shape_model (Image, ModelID, rad(0), rad(360), 0.6, 150, 0.7, 'least_squares', 0, 0.9, Row, Column, Angle, Score)
*
* Matching 01: Transform the model contours into the detected positions
dev_display (Image)
gen_empty_obj (EmptyObject)
for I := 0 to |Score| - 1 by 1
hom_mat2d_identity (HomMat2D)
hom_mat2d_rotate (HomMat2D, Angle[I], 0, 0, HomMat2D)
hom_mat2d_translate (HomMat2D, Row[I], Column[I], HomMat2D)
affine_trans_contour_xld (ModelContours, TransContours, HomMat2D)
concat_obj (EmptyObject, TransContours, EmptyObject)
* stop ()
endfor
dev_set_color ('green')
dev_display (TransContours)
*
* Matching 01: *******************************************
* Matching 01: END of generated code for model application
* Matching 01: *******************************************
*
*
* Matching 02: ************************************************
* Matching 02: BEGIN of generated code for model initialization
* Matching 02: ************************************************
set_system ('border_shape_models', 'false')
*
* Matching 02: Obtain the model image
* Matching 02: The image is assumed to be made available in the
* Matching 02: variable last displayed in the graphics window
copy_obj (Image, Image, 1, 1)
*
* Matching 02: Build the ROI from basic regions
gen_region_runs (ModelRegion, [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], [271,270,269,268,268,267,267,267,267,267,267,267,267,268,268,269,269,271,273,276,279,281,282,285,289,292,299], [290,298,309,317,321,322,323,324,325,325,326,326,326,326,326,326,326,326,325,325,324,322,321,319,317,312,308])
*
* Matching 02: Reduce the model template
reduce_domain (Image, ModelRegion, TemplateImage)
*
* Matching 02: Create the shape model
create_shape_model (TemplateImage, 3, rad(0), rad(360), 'auto', 'none', 'use_polarity', [10,11,4], 10, ModelID)
*
* Matching 02: Get the model contour for transforming it later into the image
get_shape_model_contours (ModelContours, ModelID, 1)
*
* Matching 02: Get the reference position
area_center (ModelRegion, ModelRegionArea, RefRow, RefColumn)
vector_angle_to_rigid (0, 0, 0, RefRow, RefColumn, 0, HomMat2D)
affine_trans_contour_xld (ModelContours, TransContours, HomMat2D)
*
* Matching 02: Display the model contours
dev_display (Image)
dev_set_color ('green')
dev_set_draw ('margin')
dev_display (ModelRegion)
dev_display (TransContours)
stop ()
*
* Matching 02: END of generated code for model initialization
* Matching 02: * * * * * * * * * * * * * * * * * * * * * * *
* Matching 02: BEGIN of generated code for model application
* Matching 02: The following operations are usually moved into
* Matching 02: that loop where the acquired images are processed
*
* Matching 02: Find the model
find_shape_model (Image, ModelID, rad(0), rad(360), 0.6, 0, 0.6, 'least_squares', [3,1], 0.9, Row, Column, Angle, Score)
*
* Matching 02: Transform the model contours into the detected positions
dev_display (Image)
for I := 0 to |Score| - 1 by 1
hom_mat2d_identity (HomMat2D)
hom_mat2d_rotate (HomMat2D, Angle[I], 0, 0, HomMat2D)
hom_mat2d_translate (HomMat2D, Row[I], Column[I], HomMat2D)
affine_trans_contour_xld (ModelContours, TransContours, HomMat2D)
concat_obj (EmptyObject, TransContours, EmptyObject)
dev_set_color ('green')
dev_display (TransContours)
* stop ()
endfor
*
* Matching 02: *******************************************
* Matching 02: END of generated code for model application
* Matching 02: *******************************************
*
dev_clear_window ()
dev_display (GrayImage)
dev_display (EmptyObject)
count_obj (EmptyObject, Number)
<Halcon练习>米粒计数(模板匹配)
最新推荐文章于 2023-09-29 17:31:18 发布