当前位置:网站首页>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
边栏推荐
- 【QT】制作MyComboBox点击事件
- Flutter ‘/usr/lib/libswiftCore. dylib‘ (no such file)
- left_and_right_net可解释性设计
- Solar insect killing system based on single chip microcomputer
- Appearance of LabVIEW error dialog box
- ansys命令
- LabVIEW错误对话框的出现
- Risc-v-qemu-virt in FreeRTOS_ Lock mechanism analysis of GCC
- [technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
- [matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (cosine roll off forming pulse)
猜你喜欢
Actual cases and optimization solutions of cloud native architecture
基于单片机的太阳能杀虫系统
Google Chrome browser will support the function of selecting text translation
PostgreSQL has officially surpassed mysql. Is this guy too strong!
BUU-Crypto-[GXYCTF2019]CheckIn
BUU-Crypto-Cipher
LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
光模塊字母含義及參數簡稱大全
Unity is connected to the weather system
Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology
随机推荐
Thread pool: use thread pool to optimize query speed
Flask
[matlab] general function of communication signal modulation - generation of narrow-band Gaussian white noise
企业级日志分析系统ELK(如果事与愿违那一定另有安排)
【雕爷学编程】Arduino动手做(105)---压电陶瓷振动模块
VB. Net calls ffmpeg to simply process video (class Library-6)
VB. Net GIF (making and disassembling - optimizing code, class library - 5)
[matlab] matlab simulates digital bandpass transmission system ask, PSK, FSK system
[matlab] communication signal modulation general function - low pass filter
[matlab] matlab simulates digital bandpass transmission systems - QPSK and OQPSK systems
[technology development -25]: integration technology of radio and television network, Internet, telecommunication network and power grid
空洞卷积、可变形卷积、可变形ROI Pooling
input显示当前选择的图片
SQL performance optimization skills
The data mark is a piece of fat meat, and it is not only China Manfu technology that focuses on this meat
HMS v1.0 appointment.php editid参数 SQL注入漏洞(CVE-2022-25491)
Void convolution, deformable convolution, deformable ROI pooling
Flutter calls Gaode map app to realize location search, route planning and reverse geocoding
[QT] timer
Upper computer software development - log information is stored in the database based on log4net