当前位置:网站首页>Halcon image calibration enables subsequent image processing to become the same as the template image
Halcon image calibration enables subsequent image processing to become the same as the template image
2022-07-04 05:37:00 【The little girl is so cute】
Halcon Image calibration , After the subsequent image processing, it becomes the same as the template image
Choose any picture

After the rotation correction of this picture , The image becomes a template image . Its area region The location is as shown in the figure :

When a new picture comes , Let it relate to region Compare , There is obvious deviation from the position of the formwork , As shown in the figure :

Our goal is to make this new image coincide with the template area after processing . As shown in the figure below :

In fact, the overall function is similar to rotating matting , Only the functions used are a little different .
Code aggregation :
The image used in the code is :C:\Users\HJ\AppData\Roaming\MVTec\HALCON-21.05-Progress\examples\images\blister( Install it on your own halcon To find )
* Read a picture for processing , And take the processed figure as a template , Let the following pictures look like this one
read_image (Image, 'C:/Users/HJ/Desktop/test_image/blister/blister_01.png')
threshold(Image, Region, 100, 255)
connection(Region, ConnectedRegions)
select_shape(ConnectedRegions, SelectedRegions, 'area', 'and', 15000, 9999999)
shape_trans(SelectedRegions, RegionTrans, 'convex')
* Calculation region The direction of ( angle ),Phi Is the farthest point of the area and x Angle between axes
orientation_region(RegionTrans, Phi)
* Get the center of the area
area_center(RegionTrans, Area, Row, Column)
if ((1.57<Phi and Phi<3.142) or (-3.142<Phi and Phi<-1.57))
vector_angle_to_rigid(Row, Column, Phi, Row, Column, 3.14159, HomMat2D)
else
vector_angle_to_rigid(Row, Column, Phi, Row, Column, 0, HomMat2D)
endif
* Rotate pictures and areas
affine_trans_image(Image, ImageAffineTrans, HomMat2D, 'constant', 'false')
affine_trans_region(RegionTrans, RegionTrans, HomMat2D, 'nearest_neighbor')
* Calculate the center of the area after rotation , That is, the center of the template area
area_center (RegionTrans, AreaRef, RowRef, ColumnRef)
list_files ('C:/Users/HJ/Desktop/test_image/blister', ['files','follow_links'], ImageFiles)
tuple_regexp_select (ImageFiles, ['\\.(tif|tiff|gif|bmp|jpg|jpeg|jp2|png|pcx|pgm|ppm|pbm|xwd|ima|hobj)$','ignore_case'], ImageFiles)
Width := 550
Height := 400
for Index := 0 to |ImageFiles| - 1 by 1
* Data preprocessing
read_image (Image2, ImageFiles[Index])
threshold(Image2, Region_Each, 100, 255)
connection(Region_Each, ConnectedRegions_Each)
select_shape(ConnectedRegions_Each, SelectedRegions_Each, 'area', 'and', 15000, 9999999)
shape_trans(SelectedRegions_Each, RegionTrans_Each, 'convex')
* Calculate the direction of the current area ( angle )
orientation_region(RegionTrans_Each, Phi_Each)
* Get the center of the current area
area_center(RegionTrans_Each, Area_Each, Row_Each, Column_Each)
if ((1.57<Phi_Each and Phi_Each<3.142) or (-3.142<Phi_Each and Phi_Each<-1.57))
* Use the center of the current area 、 angle and Calculate the center and angle of the template area , Generate a matrix of affine transformation
vector_angle_to_rigid(Row_Each, Column_Each, Phi_Each, RowRef, ColumnRef, 3.14159, HomMat2D1)
else
vector_angle_to_rigid(Row_Each, Column_Each, Phi_Each, RowRef, ColumnRef, 0, HomMat2D1)
endif
* Adjust the picture according to the affine transformation matrix , Become the same as the template image
affine_trans_image(Image2, ImageAffineTrans_Each, HomMat2D1, 'constant', 'false')
endfor
边栏推荐
- Remote desktop client RDP
- BUU-Crypto-Cipher
- BUU-Crypto-[GXYCTF2019]CheckIn
- 谷歌 Chrome 浏览器将支持选取文字翻译功能
- 2022g2 power station boiler stoker special operation certificate examination question bank and answers
- BUU-Reverse-easyre
- Daily question brushing record (12)
- LM small programmable controller software (based on CoDeSys) note XXI: error 3703
- How to clone objects
- [paper summary] zero shot semantic segmentation
猜你喜欢

Graduation design of small programs -- small programs of food and recipes

VB.net GIF(制作、拆解——优化代码,类库——5)

Solar insect killing system based on single chip microcomputer

Unity is connected to the weather system

Daily question brushing record (12)

Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)

1480. 一维数组的动态和
![[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre](/img/3e/b5df691ca1790469eb1b4e8ea5b4c0.png)
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre

2022 a special equipment related management (elevator) examination questions simulation examination platform operation
![[paper summary] zero shot semantic segmentation](/img/78/ee64118d86a7e43ec4d1cb97191fbe.jpg)
[paper summary] zero shot semantic segmentation
随机推荐
Thread pool: use thread pool to optimize query speed
C # character similarity comparison general class
2022 R2 mobile pressure vessel filling retraining question bank and answers
What is MQ?
19. Framebuffer application programming
19.Frambuffer应用编程
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
[untitled]
1.1 history of Statistics
Evolution of system architecture: differences and connections between SOA and microservice architecture
Daily question brushing record (12)
Just do it with your hands 7 - * project construction details 2 - hook configuration
Li Kou's 300th weekly match
【兴趣阅读】Adversarial Filtering Modeling on Long-term User Behavior Sequences for Click-Through Rate Pre
VB.net 简单的处理图片,黑白(类库——7)
c语言经典指针和数组笔试题解析
Flink1.13 basic SQL syntax (II) join operation
[matlab] general function of communication signal modulation - generation of narrow-band Gaussian white noise
BUU-Real-[PHP]XXE
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (class I part response waveform)