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

边栏推荐
- [tcapulusdb knowledge base] [list table] example code for deleting the data at the specified location in the list
- 1-1 introduction to VMWare
- redisTemplate和cacheManager操作redis有什么不同
- 第一批00后下场求职:不要误读他们的“不一样”
- AI video cloud: a good wife in the era of we media
- A summary of PostgreSQL data types. All the people are here
- The tax software exits when it detects that it is a virtual machine. How to solve this problem?
- redis 精讲系列介绍八 - 淘汰策略
- 深度学习 简介
- Tcapulusdb Jun · industry news collection (V)
猜你喜欢

直接插入排序

A summary of PostgreSQL data types. All the people are here
![[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

MySQL data recovery (.Ibdata1, bin log)

Twitter与Shopify合作 将商家产品引入Twitter购物当中

How to process large volume xlsx/csv/txt files?

AI 视频云 VS 窄带高清,谁是视频时代的宠儿

两招提升硬盘存储数据的写入效率

Efficient remote office experience | community essay solicitation

深度学习 TensorFlow入门
随机推荐
移动端城市列表排序js插件vercitylist.js
Goframe framework: quick creation of static file download web service
虫子 STM32 中断 (懂的都懂)
2022年的软件开发:首席信息官应该知道的五个现实
A summary of PostgreSQL data types. All the people are here
How to realize data transaction
mysql如何删除表的一行数据
Using jhipster to build microservice architecture
What if the self incrementing IDs of online MySQL are exhausted?
页面导出excel的三种方式
仿360桌面悬浮球插件
【LeetCode】翻转链表II
Swiftui component encyclopedia creating animated 3D card scrolling effects using Scrollview and geometryreader
Full analysis of embedded software testing tool tpt18 update
Half search method
基于HAProxy实现网页动静分离
January 17, 2022: word rule II. Give you a pattern and a character
[greed] leetcode991 Broken Calculator
d重载嵌套函数
【二叉树进阶】AVLTree - 平衡二叉搜索树