当前位置:网站首页>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

边栏推荐
- Process communication mode between different hosts -- socket
- String judgment
- Mlperf training v2.0 list released, with the same GPU configuration, the performance of Baidu PaddlePaddle ranks first in the world
- MLPerf Training v2.0 榜单发布,在同等GPU配置下百度飞桨性能世界第一
- 研究發現,跨境電商客服系統都有這五點功能!
- Global and Chinese markets of nano biosensors 2022-2028: Research Report on technology, participants, trends, market size and share
- About the problem that MySQL connector net cannot be cleared in MySQL
- solver. Learning notes of prototxt file parameters
- Global and Chinese market of peeled bourdon tubes 2022-2028: Research Report on technology, participants, trends, market size and share
- Distinction between heap and stack
猜你喜欢

Extended application of single chip microcomputer-06 independent key

Drive LED -- GPIO control

Embedded composition and route

万字详解八大排序 必读(代码+动图演示)

The printer encountered an abnormal configuration problem 0x8007007e (win10)
![C WinForm [exit application] - practice 3](/img/25/30c795cc3fa6931eb1d733719d4ad0.jpg)
C WinForm [exit application] - practice 3

MySQL - storage engine

Programming knowledge -- basis of C language

How to select conductive slip ring

Process communication mode between different hosts -- socket
随机推荐
导电滑环磨损快的原因
PIL's image tool image reduction and splicing.
Using C language to realize IIC driver in STM32 development
Global and Chinese market for blood typing 2022-2028: Research Report on technology, participants, trends, market size and share
. Net service governance flow limiting middleware -fireflysoft RateLimit
Global and Chinese markets of nano biosensors 2022-2028: Research Report on technology, participants, trends, market size and share
TCP and UDP
Rename directory in C [closed] - renaming a directory in C [closed]
Record the torch encountered by win10 cuda. is_ False problem in available()
Create inf module in AMI code
UEFI development learning 4 - getting to know variable services
Consul安装
Global and Chinese market of core pallets 2022-2028: Research Report on technology, participants, trends, market size and share
C#,数值计算(Numerical Recipes in C#),线性代数方程的求解,LU分解(LU Decomposition)源程序
Day09 how to create packages import package naming conventions Alibaba Development Manual
Altium designer 19.1.18 - clear information generated by measuring distance
Batch modify the txt file code to UTF-8 (notepad++)
The global and Chinese market of lithographic labels 2022-2028: Research Report on technology, participants, trends, market size and share
Fundamentals of C language
Threads and processes