Halcon 使用光流算子检测运动物体

2024-03-12 23:20

本文主要是介绍Halcon 使用光流算子检测运动物体,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

文章目录

  • 算子
    • optical_flow_mg 计算两个图像之间的光流
    • vector_field_length 计算向量场的向量长度
    • select_shape_std 选择给定形状的区域
    • vector_field_to_real 将矢量场图像转换为两个实值图像
    • intensity 计算灰度值的均值和偏差
    • local_max_sub_pix 以亚像素精度检测局部极大值
  • Halcon 光流算子示例
  • Halcon 获取移动物体的移动方向
  • Halcon 卫星图获取移动物体的移动方向

算子

optical_flow_mg 计算两个图像之间的光流

optical_flow_mg(ImageT1, ImageT2 : VectorField : Algorithm, SmoothingSigma, IntegrationSigma, FlowSmoothness, GradientConstancy, MGParamName, MGParamValue : )
当使用光流计算函数时,以下是参数的解释:ImageT1:输入的第一幅图像。ImageT2:输入的第二幅图像。VectorField:计算得到的光流结果,会存储在这个变量中。Algorithm:用于计算光流的算法,可以选择 'clg', 'ddraw', 'fdrig' 中的一个。SmoothingSigma:初始高斯平滑的标准差。这个参数用于控制光流计算过程中的图像平滑程度。IntegrationSigma:积分滤波器的标准差。这个参数影响了光流场的积分过程。FlowSmoothness:平滑项相对于数据项的权重。它影响了光流场的平滑程度。GradientConstancy:梯度稳定性相对于灰度稳定性的权重。这个参数用于平衡梯度稳定性和灰度稳定性在光流计算中的影响。MGParamName:多网格算法的参数名称,可以指定不同的参数名来调整多网格算法的行为。MGParamValue:多网格算法的参数值,根据实际需求进行设置。

vector_field_length 计算向量场的向量长度

vector_field_length(VectorField : Length : Mode : )
以下是各个参数的解释:VectorField:输入的矢量场,包含了需要计算长度的向量。Length:计算得到的向量长度结果将会存储在这个变量中。Mode:用于计算向量长度的模式选择参数。'length':计算向量的长度。'squared_length':计算向量的平方长度。

select_shape_std 选择给定形状的区域

select_shape_std(Regions : SelectedRegions : Shape, Percent : )
以下是各个参数的解释:Regions:输入的区域,包含需要进行选择的区域。SelectedRegions:经过选择后具有所需形状的区域将会存储在这个变量中。Shape:要检查的形状特征参数。'max_area':检查最大面积。'rectangle1':检查矩形1'rectangle2':检查矩形2。Percent:相似性度量参数,用于确定区域形状的相似度。默认值:70.0推荐值范围:10.0, 30.0, 50.0, 60.0, 70.0, 80.0, 90.0, 95.0, 100.0典型取值范围:0.0 ≤ Percent ≤ 100.0最小增量:0.1推荐增量:10.0

vector_field_to_real 将矢量场图像转换为两个实值图像

vector_field_to_real(VectorField : Row, Col : : )VectorField (输入对象): 这个参数代表一个矢量场,通常描述图像中每个点处矢量的方向和大小。Row (输出对象): 表示沿着行方向的矢量分量,指示图像中沿着行的矢量场分量。Col (输出对象): 表示沿着列方向的矢量分量,指示图像中沿着列的矢量场分量。

intensity 计算灰度值的均值和偏差

intensity(Regions, Image : : : Mean, Deviation)
参数如下:Regions (输入对象): 计算特征的区域。Image (输入对象): 灰度值图像,用于计算特征。Mean (输出控制): 区域的平均灰度值。Deviation (输出控制): 区域内灰度值的偏差

local_max_sub_pix 以亚像素精度检测局部极大值

local_max_sub_pix(Image : : Filter, Sigma, Threshold : Row, Column)
参数说明如下:Image(输入对象):单通道图像,表示输入图像。Filter(输入控制):字符串,用于计算局部导数的方法。默认值:'facet'可选值:'facet''gauss'Sigma(输入控制):实数,高斯核的标准差。如果Filter为'facet',则Sigma可以设为0.0,以避免对输入图像进行平滑处理。建议值:0.7, 0.8, 0.9, 1.0, 1.2, 1.5, 2.0, 3.0约束:Sigma >= 0.0Threshold(输入控制):实数,Hessian矩阵特征值的绝对值最小值。默认值:5.0建议值:2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0约束:Threshold >= 0.0Row(输出控制):点y数组,检测到的极大值的行坐标。Column(输出控制):点x数组,检测到的极大值的列坐标。

Halcon 光流算子示例

在这里插入图片描述

dev_update_off ()
dev_close_window ()
* Initialize the image sequence.
read_image (Image1, 'xing/xing000')
dev_open_window_fit_image (Image1, 0, 0, -1, -1, WindowHandle)
* Set the display parameters for the vector field.
dev_set_paint (['vector_field',6,1,2])
dev_set_draw ('margin')
for I := 1 to 587 by 1* Read the current image of the image sequence.read_image (Image2, 'xing/xing' + I$'03')* Compute the optical flow.* 计算光流optical_flow_mg (Image1, Image2, VectorField, 'fdrig', 0.8, 1, 8, 5, 'default_parameters', 'accurate')* Segment the optical flow vector field.* 阈值处理threshold (VectorField, Region, 1, 10000)* Display the current image of the sequence.  Note that this means that* the optical flow vectors will also be displayed at the "end" of the movement* of the objects in the image.* 显示dev_display (Image2)* Display the optical flow.dev_set_color ('yellow')dev_set_line_width (1)dev_display (VectorField)* Display the segmented optical flow.dev_set_color ('green')dev_set_line_width (3)dev_display (Region)* Copy the current image to the previous image of the sequence.* 将当前图像复制到序列的前一个图像copy_obj (Image2, Image1, 1, 1)
endfor

在这里插入图片描述

Halcon 获取移动物体的移动方向

* This example demonstrates the use of the optical flow for
* the detection of moving objects in an image sequence.
* The region of interest is analyzed to detect moving objects.
* If a moving object is detected, the exit gate is opened automatically.
* 
* Initialize output window
dev_update_off ()
read_image (Image1, 'bicycle/bicycle_01')
ZoomFactor := 0.5
* 按照指定倍数放大图像
zoom_image_factor (Image1, Image1, ZoomFactor, ZoomFactor, 'constant')
dev_close_window ()
dev_open_window_fit_image (Image1, 0, 0, -1, -1, WindowHandle)
dev_set_draw ('margin')
* 
* Generate ROI
* 产生一个xld多边形区域
gen_contour_polygon_xld (ROI, [0,0,283,348,479,479] * ZoomFactor, [0,379,379,434,639,0] * ZoomFactor)
* 产生轮廓
gen_region_contour_xld (ROI, RegionROI, 'filled')
* 裁剪
reduce_domain (Image1, RegionROI, Image1ROI)
* 
* Main loop: Calculate optical flow and display moving area
* 
for I := 2 to 27 by 1read_image (Image2, 'bicycle/bicycle_' + I$'.2')* * Zoom images to speed-up calculation of optical flow* 图片放大zoom_image_factor (Image2, Image2, ZoomFactor, ZoomFactor, 'constant')* 按照xld轮廓裁剪reduce_domain (Image2, RegionROI, Image2ROI)* 光流计算optical_flow_mg (Image1ROI, Image2ROI, VectorField, 'fdrig', 0.8, 1, 10, 5, ['default_parameters','warp_zoom_factor'], ['fast',0.8])* 计算向量场的平方长度vector_field_length (VectorField, LengthImage, 'squared_length')* * Segment regions with moving objects in the defined ROI* 计算最小灰度值min_max_gray (RegionROI, LengthImage, 0.1, Min, Max, Range)dev_display (Image2)if (Max > 2)* 阈值处理向量场threshold (LengthImage, RegionMovement, 2, Max)* 形成单独的连通域connection (RegionMovement, ConnectedRegions)* Select largest moving region* 筛选出移动的区域select_shape_std (ConnectedRegions, RegionMovement, 'max_area', 70)area_center (RegionMovement, Area, RCenterNew, CCenterNew)* 移动区域大于0if (Area > 0)* 形成一个外轮廓shape_trans (RegionMovement, ConvexHullregion, 'convex')* 外轮廓和ROI区域求交集intersection (RegionROI, ConvexHullregion, RegionMovementInROI)* 将光流图片和外轮廓裁剪reduce_domain (VectorField, ConvexHullregion, VectorReduced)* 矢量图转换为实际图vector_field_to_real (VectorReduced, Row, Column)* * Estimate the movement direction and the speed* 计算方向和速度intensity (RegionMovementInROI, Row, MeanRow, Deviation)intensity (RegionMovementInROI, Column, MeanColumn, Deviation1)* * Display resultsdev_set_line_width (1)dev_set_color ('yellow')dev_display (VectorReduced)* Display region of interestdev_set_line_width (3)dev_set_color ('magenta')dev_display (RegionROI)* Display region of moving object in the region of interestdev_set_color ('green')dev_display (RegionMovementInROI)* 产生右箭头的轮廓gen_arrow_contour_xld (Arrow, RCenterNew, CCenterNew, RCenterNew + MeanRow, CCenterNew + MeanColumn, 10, 10)dev_display (Arrow)endifendif* copy_obj (Image2ROI, Image1ROI, 1, 1)
endfor

在这里插入图片描述

Halcon 卫星图获取移动物体的移动方向

* This example demonstrates the use of the optical flow operators.
* By calculating the optical flow between two images, the
* position, speed, and movement direction of particles are calculated.
* 1. 读取图片
dev_update_off ()
dev_close_window ()
* 
read_image (Image1, 'hydraulic_engineering/hydraulic_engineering_01')
dev_open_window_fit_image (Image1, 0, 0, -1, -1, WindowHandle)
* 
dev_set_draw ('margin')
RCenter := -1
CCenter := -1
MeanR := 0
MeanC := 0
tanDir := 0
ArrowLength := 15
MinLength := 0.375
* 
for Index := 2 to 50 by 1read_image (Image2, 'hydraulic_engineering/hydraulic_engineering_' + Index$'02')* 2.估计移动粒子的区域* Calculate the optical flow between two images* 计算光流optical_flow_mg (Image1, Image2, VectorField, 'clg', 1, 1, 1000, 5, 'default_parameters', 'fast')* 计算向量场vector_field_length (VectorField, LengthImage, 'squared_length')* * Estimate the region with moving particles using the length* of the vectors of the calculated vector field** 计算灰度值min_max_gray (LengthImage, LengthImage, 0, Min, MaxLength, Range)if (MaxLength > MinLength)threshold (LengthImage, ROI, MinLength, MaxLength)* * Find the position of particles in the original image using* an estimated ROIdilation_circle (ROI, RegionDilation, 3.5)reduce_domain (Image2, RegionDilation, ImageReduced)* 获取裁剪后图片的亚像素极大值点的行列坐标local_max_sub_pix (ImageReduced, 'facet', 1.0, 4, Row, Column)* dev_set_color ('cyan')dev_set_line_width (2)if (|Row| > 0)* 产生区域点gen_region_points (Points, Row, Column)* 将点形成单独的连通域connection (Points, ConnectedRegions)* 将点膨胀dilation_circle (ConnectedRegions, PointsDilated, 2.5)* * Display found particles and their movement directions* 3.获取移动方向count_obj (PointsDilated, NumberReg)dev_display (Image2)dev_display (PointsDilated)for J := 1 to NumberReg by 1select_obj (PointsDilated, SelectedRegions, J)* * Estimate the speed of the particlesreduce_domain (VectorField, SelectedRegions, ImageReducedVF)* 将矢量图转换为两个有方向的实值图像vector_field_to_real (ImageReducedVF, RowImage, ColumnImage)* 计算 行列坐标的平均灰度值和偏差intensity (ColumnImage, ColumnImage, MeanC, Deviation)intensity (RowImage, RowImage, MeanR, Deviation)Length := sqrt(MeanR * MeanR + MeanC * MeanC)* 绘制箭头gen_arrow_contour_xld (Arrow, Row[J - 1], Column[J - 1], Row[J - 1] + MeanR / Length * ArrowLength, Column[J - 1] + MeanC / Length * ArrowLength, 5, 10)dev_display (Arrow)endforendifendifcopy_obj (Image2, Image1, 1, 1)
endfor

在这里插入图片描述

这篇关于Halcon 使用光流算子检测运动物体的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/802904

相关文章

postgresql使用UUID函数的方法

《postgresql使用UUID函数的方法》本文给大家介绍postgresql使用UUID函数的方法,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧... 目录PostgreSQL有两种生成uuid的方法。可以先通过sql查看是否已安装扩展函数,和可以安装的扩展函数

如何使用Lombok进行spring 注入

《如何使用Lombok进行spring注入》本文介绍如何用Lombok简化Spring注入,推荐优先使用setter注入,通过注解自动生成getter/setter及构造器,减少冗余代码,提升开发效... Lombok为了开发环境简化代码,好处不用多说。spring 注入方式为2种,构造器注入和setter

MySQL中比较运算符的具体使用

《MySQL中比较运算符的具体使用》本文介绍了SQL中常用的符号类型和非符号类型运算符,符号类型运算符包括等于(=)、安全等于(=)、不等于(/!=)、大小比较(,=,,=)等,感兴趣的可以了解一下... 目录符号类型运算符1. 等于运算符=2. 安全等于运算符<=>3. 不等于运算符<>或!=4. 小于运

使用zip4j实现Java中的ZIP文件加密压缩的操作方法

《使用zip4j实现Java中的ZIP文件加密压缩的操作方法》本文介绍如何通过Maven集成zip4j1.3.2库创建带密码保护的ZIP文件,涵盖依赖配置、代码示例及加密原理,确保数据安全性,感兴趣的... 目录1. zip4j库介绍和版本1.1 zip4j库概述1.2 zip4j的版本演变1.3 zip4

Python 字典 (Dictionary)使用详解

《Python字典(Dictionary)使用详解》字典是python中最重要,最常用的数据结构之一,它提供了高效的键值对存储和查找能力,:本文主要介绍Python字典(Dictionary)... 目录字典1.基本特性2.创建字典3.访问元素4.修改字典5.删除元素6.字典遍历7.字典的高级特性默认字典

使用Python构建一个高效的日志处理系统

《使用Python构建一个高效的日志处理系统》这篇文章主要为大家详细讲解了如何使用Python开发一个专业的日志分析工具,能够自动化处理、分析和可视化各类日志文件,大幅提升运维效率,需要的可以了解下... 目录环境准备工具功能概述完整代码实现代码深度解析1. 类设计与初始化2. 日志解析核心逻辑3. 文件处

一文详解如何使用Java获取PDF页面信息

《一文详解如何使用Java获取PDF页面信息》了解PDF页面属性是我们在处理文档、内容提取、打印设置或页面重组等任务时不可或缺的一环,下面我们就来看看如何使用Java语言获取这些信息吧... 目录引言一、安装和引入PDF处理库引入依赖二、获取 PDF 页数三、获取页面尺寸(宽高)四、获取页面旋转角度五、判断

C++中assign函数的使用

《C++中assign函数的使用》在C++标准模板库中,std::list等容器都提供了assign成员函数,它比操作符更灵活,支持多种初始化方式,下面就来介绍一下assign的用法,具有一定的参考价... 目录​1.assign的基本功能​​语法​2. 具体用法示例​​​(1) 填充n个相同值​​(2)

Spring StateMachine实现状态机使用示例详解

《SpringStateMachine实现状态机使用示例详解》本文介绍SpringStateMachine实现状态机的步骤,包括依赖导入、枚举定义、状态转移规则配置、上下文管理及服务调用示例,重点解... 目录什么是状态机使用示例什么是状态机状态机是计算机科学中的​​核心建模工具​​,用于描述对象在其生命

使用Python删除Excel中的行列和单元格示例详解

《使用Python删除Excel中的行列和单元格示例详解》在处理Excel数据时,删除不需要的行、列或单元格是一项常见且必要的操作,本文将使用Python脚本实现对Excel表格的高效自动化处理,感兴... 目录开发环境准备使用 python 删除 Excphpel 表格中的行删除特定行删除空白行删除含指定