当前位置:网站首页>Halcon glue line detection - template matching, pose transformation, glue width, glue continuity detection
Halcon glue line detection - template matching, pose transformation, glue width, glue continuity detection
2022-06-23 04:19:00 【beyond951】
First , Set the specifications for caliper measurement , At the same time, create a template based on image features , Used to identify the positioning image .
* Minimum glue width
MinValue:=19
MaxValue:=20
* Half the length of the caliper rectangle
MeasureLength:=20
* Half the width of the caliper rectangle
MeasureWidth:=10
* Smoothing factor
Sigma:=3
* threshold
MeasureThreshold:=80
read_image (Image1, 'D:/00-halcon Program code /1/0.bmp')
rgb1_to_gray (Image1, Image0)
get_image_size (Image0, Width, Height)
dev_close_window ()
dev_open_window (0, 0, Width/4, Height/4, 'black', WindowHandle)
dev_display (Image0)
* Create a template
gen_rectangle2 (ROI_0, 1215.5, 807.5, rad(2.32782), 492.406, 501.267)
reduce_domain (Image0, ROI_0, ImageReduced)
dev_clear_window ()
dev_display (ImageReduced)
rgb1_to_gray (ImageReduced, ImageGray)
threshold (ImageGray, Region, 220, 255)
opening_rectangle1 (Region, RegionOpening, 5, 5)
closing_rectangle1 (RegionOpening, RegionClosing, 5, 5)
connection (RegionClosing, ConnectedRegions)
select_shape (ConnectedRegions, SelectedRegions, 'area', 'and', 26051.2, 45246.8)
dilation_rectangle1 (SelectedRegions, RegionDilation, 7, 7)
area_center (RegionDilation, Area, Row, Column)
reduce_domain (ImageGray, RegionDilation, ImageReduced1)
create_scaled_shape_model (ImageReduced1, 'auto', -0.78, 0.78, 'auto', 0.7, 1.3, 'auto', 'auto', 'use_polarity', 'auto', 'auto', ModelID)
get_shape_model_contours (ModelContours, ModelID, 1)
vector_angle_to_rigid (0, 0, 0, Row, Column, 0, HomMat2D)
affine_trans_contour_xld (ModelContours, ContoursAffinTrans, HomMat2D)Created template outline , Projected onto the template image through radial transformation , It is shown in the figure :

Then based on image feature matching , After affine transformation , Maintain the pose of the template image , Create in the glue line area ROI, Measure the glue width and glue path continuity based on caliper tool .
* Read picture file
LineStartRs:=[]
LineStartCs:=[]
LineEndRs:=[]
LineEndCs:=[]
list_files ('D:/00-halcon Program code /1', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
for Index := 0 to |ImageFiles| - 1 by 1
read_image (Image, ImageFiles[Index])
rgb1_to_gray (Image, Image)
* Template matching
find_scaled_shape_model (Image, ModelID, -0.78, 0.78, 0.7, 1.3, 0.8, 1, 0.5, 'least_squares_high', 0, 0.9, Row1, Column1, Angle, Scale, Score)
* Pose correction
* Image affine transformation
vector_angle_to_rigid (Row1, Column1, Angle,Row,Column,0, HomMat2D1)
affine_trans_image (Image, ImageAffinTrans, HomMat2D1, 'constant', 'false')
* Template contour affine transformation
hom_mat2d_translate (HomMat2D1, Row1, Column1, HomMat2DTranslate)
hom_mat2d_rotate (HomMat2DTranslate, Angle, Row1, Column1, HomMat2DRotate)
hom_mat2d_scale (HomMat2DRotate, Scale, Scale, Row1, Column1, HomMat2DScale)
affine_trans_contour_xld (ModelContours, ModelTrans, HomMat2DScale)
* Display the transformed picture and outline
dev_clear_window ()
dev_display (ImageAffinTrans)
dev_set_color ('red')
dev_set_line_width (3)
dev_display (ModelTrans)
* Four corners with glue area
gen_rectangle2 (ROI_3, 1580.5, 1202.5, rad(4.28915), 80.2247, 80.1387)
gen_rectangle2 (TMP_Region, 794.5, 1176.5, rad(-86.4237), 64.1249, 75.9578)
union2 (ROI_3, TMP_Region, ROI_3)
gen_rectangle2 (TMP_Region, 824.5, 396.5, rad(-176.906), 74.108, 74.216)
union2 (ROI_3, TMP_Region, ROI_3)
gen_rectangle2 (TMP_Region, 1612.5, 420.5, rad(4.28915), 80.2247, 78.9717)
union2 (ROI_3, TMP_Region, ROI_3)
* Extract the area containing glue
gen_circle (ROI_1, 1206.96, 804.712, 426.491)
union2 (ROI_1, ROI_3, RegionUnion)
difference (ROI_0, RegionUnion, RegionDifference)
reduce_domain (ImageAffinTrans, RegionDifference, ImageReduced2)
threshold (ImageReduced2, Region1, 0, 40)
opening_rectangle1 (Region1, RegionOpening1, 7, 7)
connection (RegionOpening1, ConnectedRegions1)
select_shape (ConnectedRegions1, SelectedRegions2, 'contlength', 'and', 1000, 2000)
dilation_rectangle1 (SelectedRegions2, RegionDilation1, 21, 21)
* Perform skeleton operation on the area containing glue
* Measure with caliper according to the end point of the skeleton
for Index2 := 1 to 4 by 1
select_obj (RegionDilation1, ObjectSelected, Index2)
skeleton (ObjectSelected, Skeleton)
get_region_points (Skeleton, Rows1, Columns1)
LineStartRs[Index2-1]:=Rows1[0]
LineEndRs[Index2-1]:=Rows1[|Rows1|-1]
LineStartCs[Index2-1]:=Columns1[0]
LineEndCs[Index2-1]:=Columns1[|Columns1|-1]
endfor
* Start measuring with caliper
create_metrology_model (MetrologyHandle)
* The image size is preset , To speed up apply_metrology_model The first call of .
set_metrology_model_image_size (MetrologyHandle, Width, Height)
* Create two gauge line objects and set parameters
add_metrology_object_line_measure (MetrologyHandle, LineStartRs, LineStartCs, LineEndRs, LineEndCs, MeasureLength, MeasureWidth, Sigma, MeasureThreshold, [], [], Index3)
***** Perform a linear caliper measurement
apply_metrology_model (ImageAffinTrans, MetrologyHandle)
***** Obtain a linear caliper measuring tool
get_metrology_object_result (MetrologyHandle, 'all', 'all', 'result_type', 'all_param', Parameter)
get_metrology_object_measures (Contours5, MetrologyHandle, 'all', 'all', Row5, Column5)
* Obtain the measurement result contour
get_metrology_object_result_contour (MeasuredLines, MetrologyHandle, 'all', 'all', 1.5)
dev_clear_window ()
gen_cross_contour_xld (Cross, Row5, Column5, 6, 0.785398)
* Start to judge whether the glue width meets the requirements , Whether there is glue break 、 Wave glue
***** Show
dev_set_color ('green')
dev_set_line_width (1)
dev_display (ImageAffinTrans)
dev_display (Cross)
dev_set_color ('blue')
dev_display (MeasuredLines)
***** Clear the caliper tool handle
clear_metrology_model (MetrologyHandle)
endfor
The measurement results are shown in the figure :

边栏推荐
- 粒子动画背景登录页面particles.js
- [tcapulusdb knowledge base] [list table] sample code for inserting data into the specified position in the list
- 怎样能在小程序中实现视频通话及互动直播功能?
- Insérer le tri directement
- What is the difference between redistemplate and CacheManager operation redis
- 【LeetCode】179. Maximum number
- svg d3.js生成tree树状图
- Goframe framework: quick creation of static file download web service
- 理想汽车×OceanBase:当造车新势力遇上数据库新势力
- The tax software exits when it detects that it is a virtual machine. How to solve this problem?
猜你喜欢

Select sort method

mysql存储引擎之Myisam和Innodb的区别
![[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation](/img/eb/0d4caf0babbe14f51f4dbf1b9ae65d.png)
[machine learning] wuenda's machine learning assignment ex2 logistic regression matlab implementation

背景彩带动画插件ribbon.js

What if the self incrementing IDs of online MySQL are exhausted?

Software project management 8.4 Software project quality plan

Pytorch---使用Pytorch的预训练模型实现四种天气分类问题

深度学习 TensorFlow入门
![[Zeng shuge's laser slam notes] gmapping filter based slam](/img/93/b940ad95508d1c0d23642022df37f2.png)
[Zeng shuge's laser slam notes] gmapping filter based slam

【机器学习】 吴恩达机器学习作业 ex2逻辑回归 Matlab实现
随机推荐
d重载嵌套函数
AI video cloud vs narrowband HD, who is the favorite in the video Era
Black horse PostgreSQL, why is it black in the end
QMainWindow
【LeetCode】23. 合并K个升序链表
Adobe international certification 𞓜 how IIT Madras brings efficiency and accessibility to scholars through Adobe e Acrobat
node+express如何操作cookie
【LeetCode】两数之和II
Halcon胶线检测—模板匹配、位姿变换、胶宽,胶连续性检测
虫子 STM32 中断 (懂的都懂)
Compilation, installation and global configuration section description of haproxy
mysql常用指令
在 KubeSphere 上部署 Apache Pulsar
元素的常用事件
Not just offline caching- On how to make good use of serviceworker
AI 视频云 VS 窄带高清,谁是视频时代的宠儿
Three ways to export excel from pages
[binary tree] 993 Cousins in Binary Tree
MySQL data recovery (.Ibdata1, bin log)
[greed] leetcode991 Broken Calculator