[Halcon&定位] 解决Roi区域外的模板匹配成功 您所在的位置:网站首页 halcon算法模板匹配到搜索区域外模板 [Halcon&定位] 解决Roi区域外的模板匹配成功

[Halcon&定位] 解决Roi区域外的模板匹配成功

2024-06-29 21:19| 来源: 网络整理| 查看: 265

[Halcon&定位] 解决Roi区域外的模板匹配成功 原创

丶布布饿了 2023-12-22 20:51:37 博主文章分类:Halcon ©著作权

文章标签 计算机视觉 人工智能 匹配异常 搜索 Image 文章分类 JavaScript 前端开发

©著作权归作者所有:来自51CTO博客作者丶布布饿了的原创作品,请联系作者获取转载授权,否则将追究法律责任 作者: 丶布布

一.问题描述

[Halcon&定位] 解决Roi区域外的模板匹配成功_Image

用halcon形状模版匹配,红色矩形框是搜索范围,ROI 矩形框中间的是训练的模版,按理说应该只会匹配到ROI中中间的那个为什么会搜到搜索区域之外的部分,而且匹配分数还很高,即模板在搜索区域外仍能匹配成功。  二.原因分析

使用reduce_domain裁切搜索区域部分的图像时,只是将搜索区域以外的图像遮盖了,并不是彻底消失了。所以在参数设置没问题,匹配分数依然很高的情况下,只要模板的重心还在搜索Roi内,依然能搜索模板。  

三.解决措施

将搜索区域以外的图像彻底遮盖掉,这样即使模板的重心还在搜索Roi内,也不能匹配到搜索区域以外的图像了。

Halcon代码:

dev_close_window () dev_open_window (0, 0, 648, 512, 'black', WindowHandle) read_image (Image, '图像1.png') *建模 *draw_region (OutRegion, WindowHandle) *draw_region (InRegion, WindowHandle) *difference (OutRegion, InRegion, RegionDifference) read_region (RegionDifference, 'ModelRegion.hobj') reduce_domain (Image, RegionDifference, ImageReduced1) create_shape_model (ImageReduced1, 5, 0, 0, 'auto', 'auto', 'ignore_global_polarity', 'auto', 50, ModelID2) *匹配 read_image (Image, '图像1.png') *draw_circle (WindowHandle, Row2, Column2, Radius) gen_circle (SerRegion, 433, 620, 100) ***↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*** *这里取消掉reduce_domain得到搜索图像,而是采用paint_region方式 *reduce_domain (Image, SerRegion, ImageReduced3) get_domain (Image, Domain) difference (Domain, SerRegion, RegionDifference1) paint_region (RegionDifference1, Image, ImageReduced3, 1, 'fill') ***↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑*** find_shape_model (ImageReduced3, ModelID2, -0.39, 0.79, 0.5, 1, 0.5, 'least_squares', 0, 0.9, Row7, Column7, Angle3, Score3) get_shape_model_contours (ModelContours4, ModelID2, 1) vector_angle_to_rigid (0, 0, 0, Row7, Column7, Angle3, HomMat2D) affine_trans_contour_xld (ModelContours4, ContoursAffineTrans, HomMat2D) dev_display (Image) dev_set_color ('red') dev_display (SerRegion) dev_set_color ('green') dev_set_line_width (2) dev_display (ContoursAffineTrans)

C++源码:

if (m_RegionSer.AreaCenter(&HTuple(), &HTuple()) > 0) { //_reduceImg = _inImg.ReduceDomain(_inRegion); HObject Domain, RegionDifference; GetDomain(m_TriggerImg, &Domain); Difference(Domain, m_RegionSer, &RegionDifference); PaintRegion(RegionDifference, m_TriggerImg, &imgReduced, 0, "fill"); } else { imgReduced = m_TriggerImg; }

戳戳小手帮忙点个免费的赞吧,嘿嘿。

收藏 评论 分享 举报

上一篇:[Halcon&拟合] 直线、矩形和圆的边缘提取

下一篇:[Qt5&布局] 控件自动填满所在布局框架



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有