当前位置: 首页 > news >正文

关于halcon的可变形logo模板匹配find_local_deformable_modle_xld解释及简化匹配代码

* Prepare the local deformable model of the MVTec logo.
dev_update_off ()
Width := 256
Height := 256
*创建MVT图像(可以取代)
create_mvtec_logo_broadened (LogoImage, 0, 200, Width, Height)
*分三通道
decompose3 (LogoImage, ImageR, ImageG, ImageB)
WindowWidth := 2 * Width
WindowHeight := 2 * Height
*平滑度
Smoothness := 21
dev_close_window ()
dev_open_window (0, 0, WindowWidth, WindowHeight, 'black', WindowHandle1)
dev_display (LogoImage)set_display_font (WindowHandle1, 16, 'mono', 'true', 'false')
disp_message (WindowHandle1, 'Model image', 'window', 12, 12, 'black', 'true')
*灰度化
rgb1_to_gray (LogoImage, GrayImage)
*矩形裁剪
gen_rectangle1 (Rectangle, 82, 17, 177, 235)
*裁剪图片
reduce_domain (GrayImage, Rectangle, ImageReduced)
* 提取矩形模板域,稍后将其与搜索图像的校正版本进行比较。
crop_domain (ImageReduced, ImagePart)
* 使用use_polarity作为度量创建局部可变形模型。
create_local_deformable_model (ImageReduced, 'auto', [], [], 'auto', 1, [], 'auto', 1, [], 'auto', 'none', 'use_polarity', 'auto', 'auto', [], [], ModelID)
get_deformable_model_contours (ModelContours, ModelID, 1)
disp_continue_message (WindowHandle1, 'black', 'true')
stop ()
* 打开一个窗口,将校正后的匹配与裁剪后的模型图像进行比较。
get_image_size (ImagePart, WidthPart, HeightPart)
WindowWidthPart := 2 * WidthPart
WindowHeightPart := 2 * HeightPart
dev_open_window (0, WindowWidth + 8, WindowWidthPart * 1.5, WindowHeightPart * 1.5, 'black', WindowHandle2)
set_display_font (WindowHandle2, 16, 'mono', 'true', 'false')
* 出于演示目的,匹配被应用于搜索显示徽标的人为变形越来越大的图像。
gen_random_vector_field (VectorFieldFrom, Width, Height, 0, 2)
vector_field_to_real (VectorFieldFrom, VFFromRow, VFFromCol)
for Index := 1 to 5 by 1gen_random_vector_field (VectorFieldTo, Width, Height, 40, 2)vector_field_to_real (VectorFieldTo, VFToRow, VFToCol)for T := 0.0 to 0.95 by 0.05* 创建具有人工变形的搜索图像。create_deformed_mvtec_logo (VFFromRow, VFFromCol, VFToRow, VFToCol, ImageR, ImageG, ImageB, SearchImage, T)rgb1_to_gray (SearchImage, GrayImage)* 在变形的搜索图像中查找模型。因此校正图像、相应的矢量场和变形图像应返回已找到的模型实例的轮廓。count_seconds (Seconds1)find_local_deformable_model (GrayImage, ImageRectified, VectorField, DeformedContours, ModelID, 0, 0, 1, 1, 1, 1, 0.5, 1, 1, 4, 0.9, ['image_rectified', 'vector_field', 'deformed_contours'], ['deformation_smoothness', 'expand_border', 'subpixel'], [Smoothness,0, 1], Score, Row, Column)count_seconds (Seconds2)Time := 1000.0 * (Seconds2 - Seconds1)dev_set_window (WindowHandle1)* 对于可视化,我们使用返回的向量场并在搜索图像中生成变形网格。gen_warped_mesh (VectorField, WarpedMesh, 10)dev_display (SearchImage)dev_set_color ('yellow')dev_set_line_width (1)dev_display (WarpedMesh)dev_set_line_width (3)dev_set_color ('green')dev_display (DeformedContours)disp_message (WindowHandle1, 'Match found in ' + Time$'3.1f' + ' ms (Score: ' + Score$'3.2f' + ')', 'window', 12, 12, 'black', 'true')dev_set_window (WindowHandle2)* 为了可视化校正后的搜索图像和原始模型区域之间的差异,使用了绝对差异。abs_diff_image (ImagePart, ImageRectified, ImageAbsDiff1, 1)dev_display (ImageAbsDiff1)disp_message (WindowHandle2, 'Difference between model image and rectified image', 'window', 12, 12, 'black', 'true')* 通过使用光流(取消以下行的注释),可以进一步减小校正后的搜索图像和l模型区域之间的差异。optical_flow_mg (ImagePart, ImageRectified, VectorField1, 'clg', 0.8, 1, 20, 5, 'default_parameters', 'very_accurate')unwarp_image_vector_field (ImageRectified, VectorField1, ImageUnwarped)vector_field_to_real (VectorField1, RowField, ColField)vector_field_length (VectorField1, Length, 'length')abs_diff_image (ImagePart, ImageUnwarped, ImageAbsDiff, 1)
*        stop ()dev_display (ImageAbsDiff1)endforcopy_obj (VFToRow, VFFromRow, 1, 1)copy_obj (VFToCol, VFFromCol, 1, 1)
endfor

二.简化代码和资料包

read_image (Jl01, 'C:/Users/user/Desktop/Halcon-Study/可变形模板匹配/JL_01.bmp')
gen_rectangle2 (ROI_0, 2123.53, 2151.85, rad(-80.7904), 275.892, 249.703)
rgb1_to_gray(Jl01, GrayImage1)
reduce_domain(GrayImage1, ROI_0, ImageReduced)crop_domain (ImageReduced, ImagePart)
create_local_deformable_model (ImageReduced, 'auto', [], [], 'auto', 1, [], 'auto', 1, [], 'auto', 'none', 'use_polarity', 'auto', 'auto', [], [], ModelID)
get_deformable_model_contours (ModelContours, ModelID, 1)
find_local_deformable_model (GrayImage1, ImageRectified, VectorField, DeformedContours, ModelID, 0, 359, 1,1,1, 1, 0.9, 8, 0.01, 6, 0.9, ['image_rectified', 'vector_field', 'deformed_contours'], ['deformation_smoothness', 'expand_border', 'subpixel'], [21,0, 1], Score, Row, Column)Step:=50
gen_empty_obj (WarpedMesh)
count_obj (VectorField, Number)
for Index := 1 to Number by 1* For visualization we use the returned vector field* and generate a grid of the deformation in the search image.select_obj (VectorField, ObjectSelected, Index)vector_field_to_real (ObjectSelected, DRow, DCol)vector_field_to_hom_mat2d(ObjectSelected, HomMat2D)hom_mat2d_to_affine_par(HomMat2D, Sx, Sy, Phi, Theta, Tx, Ty)get_image_size (VectorField, Width, Height)for ContR := 0.5 to Height[0] - 1 by StepCol1 := [0.5:Width[0] - 1]tuple_gen_const (Width[0] - 1, ContR, Row1)get_grayval_interpolated (DRow, Row1, Col1, 'bilinear', GrayRow)get_grayval_interpolated (DCol, Row1, Col1, 'bilinear', GrayCol)gen_contour_polygon_xld (Contour, GrayRow, GrayCol)concat_obj (WarpedMesh, Contour, WarpedMesh)endforfor ContC := 0.5 to Width[0] - 1 by StepRow1 := [0.5:Height[0] - 1]tuple_gen_const (Height[0] - 1, ContC, Col1)get_grayval_interpolated (DRow, Row1, Col1, 'bilinear', GrayRow)get_grayval_interpolated (DCol, Row1, Col1, 'bilinear', GrayCol)gen_contour_polygon_xld (Contour, GrayRow, GrayCol)concat_obj (WarpedMesh, Contour, WarpedMesh)endfor
endfordev_display (GrayImage1)dev_set_color ('yellow')dev_set_line_width (1)dev_display (WarpedMesh)dev_set_line_width (3)dev_set_color ('green')dev_display (DeformedContours)


http://www.mrgr.cn/news/65280.html

相关文章:

  • Android沙箱
  • 《欢乐饭米粒儿9》第五期:用笑声诠释生活,让爱成为日常
  • 堆heap的讨论、习题与代码
  • 第三十二章 Vue组件分类及存放位置
  • Kafka 客户端工具使用分享【offsetexplorer】
  • 【运动的&足球】足球场景目标检测系统源码&数据集全套:改进yolo11-ASF-P2
  • JavaScript函数
  • 物联网赋能的人工智能图像检测系统
  • 探索 Python 的新天地:Helium 库揭秘
  • 代码随想录训练营Day15 | 530.二叉搜索树的最小绝对差 - 501.二叉搜索树中的众数 - 236. 二叉树的最近公共祖先
  • 15.函数的重载
  • 04741计算机网络原理真题-CRC的计算-案例分析
  • PHP+MySQL开发的一套招聘管理系统开发案例源码功能介绍
  • H5页面在线预览pdf
  • 照明灯十大知名品牌有哪些?2024灯具十大公认品牌排行榜出炉!
  • SpringMVC课时2
  • FFmpeg 4.3 音视频-多路H265监控录放C++开发十. 多线程控制帧率。循环播放,QT connect 细节,
  • SpringBoot新闻稿件管理系统:开发与实践
  • 亚马逊营销邮件:高效策略提升邮件转化率!
  • 前端项目配置文件的各种配置
  • STM32HAL-最简单的长、短、多击按键框架(多按键)
  • 百度社招内推
  • ‌RS485是什么?
  • 拼多多2025秋招多模态大模型搜广推面试题
  • 基于MySQL的企业专利数据高效查询与统计实现
  • 城市防洪新篇章:城市内涝一维二维耦合模拟;水动力模型;水质模拟;海绵城市关键控制指标计算;城市排水系统,SWMM模型;慧天内涝软件