当前位置:网站首页>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
边栏推荐
- How to clone objects
- LM small programmable controller software (based on CoDeSys) note XXI: error 3703
- 简易零钱通
- Flutter calls Gaode map app to realize location search, route planning and reverse geocoding
- Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
- Zzulioj:1201: mode problem
- (4) Canal multi instance use
- (4) Canal multi instance use
- Yyds dry goods inventory TCP & UDP
- 2022年A特种设备相关管理(电梯)考试题模拟考试平台操作
猜你喜欢

光模块字母含义及参数简称大全

Solar insect killing system based on single chip microcomputer

Write a complete answer applet (including single choice questions, judgment questions and multiple topics) (III) single choice questions, judgment questions, and the first question display

Simulink and Arduino serial port communication

VB. Net GIF (making and disassembling - optimizing code, class library - 5)

1480. Dynamic sum of one-dimensional array

基于单片机的太阳能杀虫系统

Build an Internet of things infrared temperature measuring punch in machine with esp32 / rush to work after the Spring Festival? Baa, no matter how hard you work, you must take your temperature first

VB.net 简单的处理图片,黑白(类库——7)

Introduction to AMBA
随机推荐
Unity2D--人物移动并转身
XII Golang others
简易零钱通
Flink1.13 SQL basic syntax (I) DDL, DML
C # character similarity comparison general class
Supplement the JS of a video website to decrypt the video
【QT】制作MyComboBox点击事件
Solar insect killing system based on single chip microcomputer
Programmers don't talk about morality, and use multithreading for Heisi's girlfriend
光模塊字母含義及參數簡稱大全
(4) Canal multi instance use
VB.net GIF(制作、拆解——优化代码,类库——5)
TCP state transition diagram
Li Kou's 300th weekly match
2022危险化学品经营单位安全管理人员上岗证题库及答案
Letter meaning and parameter abbreviation of optical module Daquan
[QT] create mycombobox click event
Unity2d -- character moves and turns
1480. Dynamic sum of one-dimensional array
Ping port artifact psping