当前位置:网站首页>Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
Shape template matching based on Halcon learning [viii] PM_ multiple_ models. Hdev routine
2022-07-05 07:55:00 【BoomBiuBiu】
* This sample program demonstrates how to use HALCON Shape based matching , Find multiple different models in one call to find _shape_ Model . Please note that this is a frequently useful mode of operation .
Multi template matching routine
* Turn off computer updates during program execution .
dev_update_pc ('off')
* During the execution of the shutdown program , Switch the automatic output of the icon output object to the graphics window .
dev_update_window ('off')
* Close the update of the variable window during program execution .
dev_update_var ('off')
* close window
dev_close_window ()
* Open a new window
dev_open_window (0, 0, 646, 482, 'black', WindowHandle)
* Adaptive picture
dev_set_part (0, 0, 481, 645)
* Set parameters
set_display_font (WindowHandle, 20, 'mono', 'true', 'false')
dev_set_draw ('margin')
dev_set_line_width (3)
* These colors will be used to graphically identify different models in the following visualization code .
Colors := ['red','green','cyan']
* The model will be generated from a hard coded rectangle given by the following coordinates :
Row1 := [135,150,185]
Column1 := [250,170,220]
Row2 := [375,310,335]
Column2 := [355,395,375]
* The object model will contain a set of XLD outline . They are used below to overlay the found model on the current image .
* Use XLD Contours are because they can transform faster than regions . This will cause a small problem , Because there are usually multiple XLD
* Contour lines will represent a model . Therefore, different models will be stored in IndexS and IndexE in .
* Set an empty array
gen_empty_obj (Models)
IndexS := []
IndexE := []
* Variable ModelIDs Include the different models created below .
ModelIDs := []
* Again ,RowsRef and ColumnsRef Store reference points for different models .
* They are necessary to transform the model into an instance found in the current image .
for J := 1 to 3 by 1
* Read the picture
read_image (Image, 'metal-parts/metal-part-model-' + J$'02d')
dev_display (Image)
dev_set_color ('green')
* Set the position of the text cursor
set_tposition (WindowHandle, 20, 20)
* Print text in the window .
write_string (WindowHandle, 'Generating shape model ' + J$'d')
* use ROI Draw rectangular matting
gen_rectangle1 (Rectangle, Row1[J - 1], Column1[J - 1], Row2[J - 1], Column2[J - 1])
* Get row and column coordinates
area_center (Rectangle, Area, Row, Column)
* Cutout
reduce_domain (Image, Rectangle, ImageReduced)
* Form different connected domains
connection (ModelRegions, ConnectedRegions)
* Select according to the area characteristics
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 20, 100000)
* Joint region
union1 (SelectedRegions, ModelRegions)
* Convert the skeleton to XLD outline .
gen_contours_skeleton_xld (ModelRegions, ModelContours, 1, 'filter')
* Set the color
dev_set_color ('red')
dev_display (ModelContours)
* Create a template
create_shape_model (ImageReduced, 5, rad(0), rad(360), 'auto', 'pregeneration', 'use_polarity', 30, 7, ModelID)
* Get the outline of the template
get_shape_model_contours (ModelCont, ModelID, 1)
* Returns the outline representation of the shape model .
select_shape_xld (ModelCont, ModelContours, 'contlength', 'and', 20, 1000)
* Calculate the current model and how many in the model XLD Contour stored model . This is calculation Index and IndexE Necessary .
*Models The above defines null
count_obj (ModelContours, NumModel)
* Calculate the outline of the existing container
count_obj (Models, NumModels)
* Similar to building a container , Put the outline of the control in
concat_obj (Models, ModelContours, Models)
*
IndexS := [IndexS,NumModels + 1]
* The number represents the number of contours
IndexE := [IndexE,NumModels + NumModel]
* Model handle
ModelIDs := [ModelIDs,ModelID]
endfor
dev_set_color ('yellow')
* Set the position of the text cursor .
set_tposition (WindowHandle, 50, 20)
* Display text on the window
write_string (WindowHandle, 'Press left button to start')
set_tposition (WindowHandle, 80, 20)
write_string (WindowHandle, 'and stop the demo.')
* Wait for the mouse button to press .
get_mbutton (WindowHandle, Row3, Column3, Button1)
wait_seconds (0.5)
dev_set_color ('red')
* Define some parameters
Button := 0
ImgNo := 1
while (Button != 1)
* Read the picture
read_image (Image, 'metal-parts/metal-parts-' + ImgNo$'02d')
* Calculate the time before recognition
count_seconds (S1)
* Note that this is models
find_shape_models (Image, ModelIDs, rad(0), rad(360), 0.5, 0, 0.5, 'least_squares', 0, 0.8, Row, Column, Angle, Score, Model)
* Calculate the time after recognition
count_seconds (S2)
Time := (S2 - S1) * 1000
dev_display (Image)
* Define how many objects there are
Num := |Score|
for J := 0 to Num - 1 by 1
** Select the correct... From the model object XLD outline .
* Copy HALCON Icon objects in the database .
copy_obj (Models, ModelSelected, IndexS[Model[J]], IndexE[Model[J]] - IndexS[Model[J]] + 1)
* Affine transformation
vector_angle_to_rigid (0, 0, 0, Row[J], Column[J], Angle[J], HomMat2D)
affine_trans_contour_xld (ModelSelected, ModelTrans, HomMat2D)
dev_set_color (Colors[Model[J]])
dev_display (ModelTrans)
endfor
dev_set_color ('yellow')
set_tposition (WindowHandle, 20, 20)
if (Num == 1)
write_string (WindowHandle, Num$'1d' + ' object found in ' + Time$'4.2f' + 'ms')
else
write_string (WindowHandle, Num$'1d' + ' objects found in ' + Time$'4.2f' + 'ms')
endif
ImgNo := ImgNo + 1
if (ImgNo > 15)
ImgNo := 1
endif
dev_error_var (Error, 1)
dev_set_check ('~give_error')
get_mposition (WindowHandle, R, C, Button)
dev_error_var (Error, 0)
dev_set_check ('give_error')
if (Error != H_MSG_TRUE)
Button := 0
endif
endwhile
for J := 0 to |ModelIDs| - 1 by 1
clear_shape_model (ModelIDs[J])
endfor
边栏推荐
- Makefile application
- 1089 Insert or Merge 含测试点5
- High end electronic chips help upgrade traditional oil particle monitoring
- [professional literacy] core conferences and periodicals in the field of integrated circuits
- Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
- 1089 insert or merge, including test point 5
- PIL's image tool image reduction and splicing.
- Network communication model -- Network OSI tcp/ip layering
- .NET服务治理之限流中间件-FireflySoft.RateLimit
- Create inf module in AMI code
猜你喜欢
Altium Designer 19.1.18 - 清除测量距离产生的信息
Altium Designer 19.1.18 - 更改铺铜的透明度
Improve lighting C program
High end electronic chips help upgrade traditional oil particle monitoring
Logistic regression: the most basic neural network
生产中影响滑环质量的因素
Network communication model -- Network OSI tcp/ip layering
Programming knowledge -- basis of C language
About the problem that MySQL connector net cannot be cleared in MySQL
Altium designer 19.1.18 - clear information generated by measuring distance
随机推荐
How to realize audit trail in particle counter software
Query the table name used by kettle in Oracle
Realization of binary relation of discrete mathematics with C language and its properties
Ten thousand words detailed eight sorting must read (code + dynamic diagram demonstration)
Nombre - 1. Création de tableaux
Cadence learning records
Embedded AI intelligent technology liquid particle counter
Define in and define out
Threads and processes
High end electronic chips help upgrade traditional oil particle monitoring
Development tools -- gcc compiler usage
From then on, I understand convolutional neural network (CNN)
Extern keyword function
Explain STM32 startup file in detail
UEFI development learning 2 - running ovmf in QEMU
Global and Chinese markets of large aperture scintillators 2022-2028: Research Report on technology, participants, trends, market size and share
Beijing Winter Olympics opening ceremony display equipment record 3
UEFI development learning 6 - creation of protocol
Interview catalogue
Basic embedded concepts