当前位置:网站首页>Halcon图片标定,使得后续图片处理过后变成与模板图片一样
Halcon图片标定,使得后续图片处理过后变成与模板图片一样
2022-07-04 05:14:00 【小女孩真可爱】
Halcon图片标定,使得后续图片处理过后变成与模板图片一样
随便选择一张图片

对这张图片进行旋转矫正之后,图片就变成了一个模板图片。它的区域region位置如图所示:

当来了一张新的图片的时候,让它与region比较,与模板的位置有明显的偏差, 如图所示:

我们的目标就是让这张新的图片经过处理后与模板区域重合。如下图所示:

其实总体功能和旋转抠图差不多,只是使用的函数有一点差异。
代码总合:
代码所用的图片在:C:\Users\HJ\AppData\Roaming\MVTec\HALCON-21.05-Progress\examples\images\blister(根据自己安装halcon的位置来寻找)
*读取一张图进行处理,并以处理后的图为模板,让后续的图片都办成这张图的模样
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')
*计算region的方向(角度),Phi是区域最远处点和x轴的夹角
orientation_region(RegionTrans, Phi)
*获取区域的中心
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
*旋转图片和区域
affine_trans_image(Image, ImageAffineTrans, HomMat2D, 'constant', 'false')
affine_trans_region(RegionTrans, RegionTrans, HomMat2D, 'nearest_neighbor')
*计算旋转之后的区域的中心, 也就是模板区域的中心
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
*数据前处理
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')
*计算当前区域的方向(角度)
orientation_region(RegionTrans_Each, Phi_Each)
*获取当前区域的中心
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))
*利用当前区域的中心、角度 和 模板区域的中心和角度来进行计算, 生成一个仿射变换的矩阵
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
*根据仿射变换矩阵来对图片进行调整,变成和模板图片一样的
affine_trans_image(Image2, ImageAffineTrans_Each, HomMat2D1, 'constant', 'false')
endfor
边栏推荐
- LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703
- 【兴趣阅读】Adversarial Filtering Modeling on Long-term User Behavior Sequences for Click-Through Rate Pre
- Supplement the JS of a video website to decrypt the video
- Flutter calls Gaode map app to realize location search, route planning and reverse geocoding
- Remote desktop client RDP
- [matlab] communication signal modulation general function - low pass filter
- Void convolution, deformable convolution, deformable ROI pooling
- 2022危险化学品经营单位安全管理人员上岗证题库及答案
- FreeRTOS 中 RISC-V-Qemu-virt_GCC 的 锁机制 分析
- Character types of C language
猜你喜欢

Zhanrui tankbang | jointly build, cooperate and win-win zhanrui core ecology

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

拓扑排序和关键路径的图形化显示
![[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk](/img/b9/cf4db4f8a5d2ef3fb344258f0e30f5.jpg)
[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk

KMP match string

谷歌 Chrome 浏览器将支持选取文字翻译功能

LM small programmable controller software (based on CoDeSys) note 22: error 4268/4052

19.Frambuffer应用编程

LM小型可编程控制器软件(基于CoDeSys)笔记二十一:错误3703

Analysis of classical pointer and array written test questions in C language
随机推荐
[QT] timer
如何使用postman实现简单的接口关联【增删改查】
[matlab] general function of communication signal modulation Fourier transform
We believe that the development of consumer Internet will still be limited to the Internet industry itself
Simulink and Arduino serial port communication
Flutter calls Gaode map app to realize location search, route planning and reverse geocoding
PostgreSQL has officially surpassed mysql. Is this guy too strong!
C language simple student management system (including source code)
企业级日志分析系统ELK(如果事与愿违那一定另有安排)
Zhongke Panyun - module a infrastructure setting and safety reinforcement scoring standard
【QT】制作MyComboBox点击事件
[interested reading] advantageous filtering modeling on long term user behavior sequences for click through rate pre
2022年R2移动式压力容器充装复训题库及答案
BUU-Crypto-[GXYCTF2019]CheckIn
Li Kou's 300th weekly match
c语言经典指针和数组笔试题解析
力扣 第 300 场周赛
[matlab] matlab simulates digital baseband transmission system eye diagram of bipolar baseband signal (cosine roll off forming pulse)
Appearance of LabVIEW error dialog box
[high concurrency, high performance and high availability of massive data MySQL practice-7] - memory data drop disk