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

边栏推荐
- Global and Chinese market of plastic recycling machines 2022-2028: Research Report on technology, participants, trends, market size and share
- From then on, I understand convolutional neural network (CNN)
- 万字详解八大排序 必读(代码+动图演示)
- Summary of STM32 serial port sending and receiving data methods
- The printer encountered an abnormal configuration problem 0x8007007e (win10)
- Global and Chinese markets of large aperture scintillators 2022-2028: Research Report on technology, participants, trends, market size and share
- Pointnet++ classification practice
- Significance and requirements of semiconductor particle control
- Good websites need to be read carefully
- STM32 knowledge points
猜你喜欢

导电滑环磨损快的原因

Improve lighting C program

Altium designer 19.1.18 - Import frame

Altium designer 19.1.18 - change the transparency of copper laying

C language uses arrays to realize the intersection, union, difference and complement of sets

Logistic regression: the most basic neural network
![C WinForm [exit application] - practice 3](/img/25/30c795cc3fa6931eb1d733719d4ad0.jpg)
C WinForm [exit application] - practice 3

Numpy——1.數組的創建

Application of ultra pure water particle counter in electronic semiconductors

Scm-05 basis of independent keyboard
随机推荐
Explain STM32 startup file in detail
Altium designer learning (I)
RF ride side door processing of prompt box
Could NOT find XXX (missing: XXX_LIBRARY XXX_DIR)
How to define guid in AMI code
Count and sort the occurrence times of specific fields through SQL statements
[professional literacy] specific direction of analog integrated circuits
Logistic regression: the most basic neural network
万字详解八大排序 必读(代码+动图演示)
C language uses arrays to realize the intersection, union, difference and complement of sets
Global and Chinese market of digital shore durometer 2022-2028: Research Report on technology, participants, trends, market size and share
Openxlsx field reading problem
Some tips for using source insight (solve the problem of selecting all)
UEFI development learning 3 - create UEFI program
STM32 learning method
1089 Insert or Merge 含测试点5
PIL's image tool image reduction and splicing.
UEFI development learning 2 - running ovmf in QEMU
Global and Chinese market of resistivity meter 2022-2028: Research Report on technology, participants, trends, market size and share
Win10 shortcut key