Halcon模板匹配中模板的保存和读取
Halcon模板匹配中模板的保存和读取
⼀保存:write_shape_model (ModelID, 'C:/Users/123/Desktop/ocr/matching.shm')
write_shape_model (ModelID, 'C:/Users/123/Desktop/ocr/matching.shm')
⼆读取read_shape_model ('C:/Users/123/Desktop/ocr/matching.shm', ModelID)
read_shape_model ('C:/Users/123/Desktop/ocr/matching.shm', ModelID)
get_shape_model_contours (ModelContours, ModelID,1)
实例:保存
*
* 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
read_image (Image, 'C:/Users/29939/Desktop/ocr/QQ图⽚20210927213156.jpg')
*
* Matching 01: Build the ROI from basic regions
gen_rectangle1 (ModelRegion, 340.467, 409.747, 402.461, 485.535)
gen_rectangle1 (_TmpRegion, 255.633, 1151.16, 337.204, 1348.87)
union2 (ModelRegion, _TmpRegion, ModelRegion)
gen_rectangle1 (_TmpRegion, 249.107, 1467.49, 343.73, 1645.43)
union2 (ModelRegion, _TmpRegion, ModelRegion)
*
* Matching 01: Reduce the model template
reduce_domain (Image, ModelRegion, TemplateImage)
*
* Matching 01: Create the shape model
create_scaled_shape_model (TemplateImage,5,rad(0),rad(360),rad(0.1324),0.92,1.09,0.0023,['point_reduction_medium','no_pregeneration'], 'use_p olarity',[5,13,16],4, ModelID)
*
* Matching 01: Get the model contour for transforming it later into the image
get_shape_model_contours (ModelContours, ModelID, 1)
write_shape_model (ModelID, 'C:/Users/123/Desktop/ocr/matching.shm')
*2
* 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: Loop over all specified test images
TestImages :=['C:/Users/29939/Desktop/ocr/QQ图⽚20210927213203.jpg','C:/Users/29939/Desktop/ocr/QQ图⽚20210927213136.jpg','C:/Users/29939/De
TestImages :=['C:/Users/29939/Desktop/ocr/QQ图⽚20210927213203.jpg','C:/Users/29939/Desktop/
ocr/QQ图⽚20210927213136.jpg','C:/Users/29939/De sktop/ocr/QQ图⽚20210927213156.jpg']
for T :=0 to 2by12
*
* Matching 01: Obtain the test image
read_image (Image, TestImages[T])
*
* Matching 01: Find the model
find_scaled_shape_model (Image, ModelID,rad(0),rad(360),0.92,1.09,0.36,5,0.5, 'least_squares',[5,1],1, Row, Column, Angle, Scale, Score)
*
* Matching 01: Transform the model contours into the detected positions
dev_display (Image)
for I :=0 to |Score|-1by1
hom_mat2d_identity (HomMat2D)
hom_mat2d_scale (HomMat2D, Scale[I], Scale[I],0,0, 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)generated
dev_set_color ('green')
dev_display (TransContours)
stop ()
endfor
endfor
*
* Matching 01: Clear model when done
stop ()
clear_shape_model (ModelID)
* Matching 01:*******************************************
* Matching 01: END of generated code for model application
* Matching 01:*******************************************
*
实例:读取
read_shape_model ('C:/Users/29939/Desktop/ocr/matching.shm', ModelID)
get_shape_model_contours (ModelContours, ModelID,1)
*
* Matching 01: END of generated code for model initialization
* Matching 01:***********************
* Matching 01: BEGIN of generated code for model application
*
* Matching 01: Loop over all specified test images
TestImages :=['C:/Users/39/Desktop/ocr/QQ图⽚20210927213203.jpg','C:/Users/39/Desktop/ocr/QQ图⽚20210927213136.jpg','C:/Users/39/Desktop/ocr/Q Q图⽚20210927213156.jpg']
for T :=0 to 2by12
*
* Matching 01: Obtain the test image
read_image (Image, TestImages[T])
*
* Matching 01: Find the model
find_scaled_shape_model (Image, ModelID,rad(0),rad(360),0.92,1.09,0.36,5,0.5, 'least_squares',[5,1],1, Row, Column, Angle, Scale, Score)
*
* Matching 01: Transform the model contours into the detected positions
dev_display (Image)
for I :=0 to |Score|-1by1
hom_mat2d_identity (HomMat2D)
hom_mat2d_scale (HomMat2D, Scale[I], Scale[I],0,0, 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)
dev_set_color ('green')
dev_display (TransContours)
stop ()
endfor
endfor
*
* Matching 01: Clear model when done
stop ()
clear_shape_model (ModelID)
* Matching 01:*******************************************
* Matching 01: END of generated code for model application
* Matching 01:*******************************************
*

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。