create_bg_estiT_create_bg_estiCreateBgEstiCreateBgEsticreate_bg_esti创建背景估计(算子)
名称
create_bg_estiT_create_bg_estiCreateBgEstiCreateBgEsticreate_bg_esti — 生成并初始化背景估计的数据集。
签名
Herror T_create_bg_esti(const Hobject InitializeImage, const Htuple Syspar1, const Htuple Syspar2, const Htuple GainMode, const Htuple Gain1, const Htuple Gain2, const Htuple AdaptMode, const Htuple MinDiff, const Htuple StatNum, const Htuple ConfidenceC, const Htuple TimeC, Htuple* BgEstiHandle)
void CreateBgEsti(const HObject& InitializeImage, const HTuple& Syspar1, const HTuple& Syspar2, const HTuple& GainMode, const HTuple& Gain1, const HTuple& Gain2, const HTuple& AdaptMode, const HTuple& MinDiff, const HTuple& StatNum, const HTuple& ConfidenceC, const HTuple& TimeC, HTuple* BgEstiHandle)
HBgEsti HImage::CreateBgEsti(double Syspar1, double Syspar2, const HString& GainMode, double Gain1, double Gain2, const HString& AdaptMode, double MinDiff, Hlong StatNum, double ConfidenceC, double TimeC) const
HBgEsti HImage::CreateBgEsti(double Syspar1, double Syspar2, const char* GainMode, double Gain1, double Gain2, const char* AdaptMode, double MinDiff, Hlong StatNum, double ConfidenceC, double TimeC) const
HBgEsti HImage::CreateBgEsti(double Syspar1, double Syspar2, const wchar_t* GainMode, double Gain1, double Gain2, const wchar_t* AdaptMode, double MinDiff, Hlong StatNum, double ConfidenceC, double TimeC) const
(
Windows only)
void HBgEsti::HBgEsti(const HImage& InitializeImage, double Syspar1, double Syspar2, const HString& GainMode, double Gain1, double Gain2, const HString& AdaptMode, double MinDiff, Hlong StatNum, double ConfidenceC, double TimeC)
void HBgEsti::HBgEsti(const HImage& InitializeImage, double Syspar1, double Syspar2, const char* GainMode, double Gain1, double Gain2, const char* AdaptMode, double MinDiff, Hlong StatNum, double ConfidenceC, double TimeC)
void HBgEsti::HBgEsti(const HImage& InitializeImage, double Syspar1, double Syspar2, const wchar_t* GainMode, double Gain1, double Gain2, const wchar_t* AdaptMode, double MinDiff, Hlong StatNum, double ConfidenceC, double TimeC)
(
Windows only)
void HBgEsti::CreateBgEsti(const HImage& InitializeImage, double Syspar1, double Syspar2, const HString& GainMode, double Gain1, double Gain2, const HString& AdaptMode, double MinDiff, Hlong StatNum, double ConfidenceC, double TimeC)
void HBgEsti::CreateBgEsti(const HImage& InitializeImage, double Syspar1, double Syspar2, const char* GainMode, double Gain1, double Gain2, const char* AdaptMode, double MinDiff, Hlong StatNum, double ConfidenceC, double TimeC)
void HBgEsti::CreateBgEsti(const HImage& InitializeImage, double Syspar1, double Syspar2, const wchar_t* GainMode, double Gain1, double Gain2, const wchar_t* AdaptMode, double MinDiff, Hlong StatNum, double ConfidenceC, double TimeC)
(
Windows only)
static void HOperatorSet.CreateBgEsti(HObject initializeImage, HTuple syspar1, HTuple syspar2, HTuple gainMode, HTuple gain1, HTuple gain2, HTuple adaptMode, HTuple minDiff, HTuple statNum, HTuple confidenceC, HTuple timeC, out HTuple bgEstiHandle)
HBgEsti HImage.CreateBgEsti(double syspar1, double syspar2, string gainMode, double gain1, double gain2, string adaptMode, double minDiff, int statNum, double confidenceC, double timeC)
public HBgEsti(HImage initializeImage, double syspar1, double syspar2, string gainMode, double gain1, double gain2, string adaptMode, double minDiff, int statNum, double confidenceC, double timeC)
void HBgEsti.CreateBgEsti(HImage initializeImage, double syspar1, double syspar2, string gainMode, double gain1, double gain2, string adaptMode, double minDiff, int statNum, double confidenceC, double timeC)
def create_bg_esti(initialize_image: HObject, syspar_1: float, syspar_2: float, gain_mode: str, gain_1: float, gain_2: float, adapt_mode: str, min_diff: float, stat_num: int, confidence_c: float, time_c: float) -> HHandle
描述
create_bg_esticreate_bg_estiCreateBgEstiCreateBgEstiCreateBgEsticreate_bg_esti 创建用于背景估计的新数据集,并使用适当参数进行初始化。估计的背景图像属于该数据集的一部分。新创建的数据集将自动成为当前数据集。
InitializeImageInitializeImageInitializeImageInitializeImageinitializeImageinitialize_image 用于作为背景图像的初始预测。为获得良好预测效果,应向
InitializeImageInitializeImageInitializeImageInitializeImageinitializeImageinitialize_image 传递不含移动对象的场景图像。这样可将前景适应率保持在较低水平。若无空场景图像可用,可改用均匀灰度图像替代。此时需提高前景图像的自适应速率,因为初始阶段图像大部分区域会被识别为前景。初始化图像必须为 byte 或 real。由于处理单通道图像,需为每个通道创建数据集。InitializeImageInitializeImageInitializeImageInitializeImageinitializeImageinitialize_image 的尺寸与区域将决定使用该数据集进行所有背景估计(run_bg_estirun_bg_estiRunBgEstiRunBgEstiRunBgEstirun_bg_esti)的尺寸与区域范围。
Syspar1Syspar1Syspar1Syspar1syspar1syspar_1 和 Syspar2Syspar2Syspar2Syspar2syspar2syspar_2 是卡尔曼系统矩阵的参数。该系统矩阵根据卡尔曼滤波理论描述了灰度值变化的系统。背景估计器为每个像素实现了不同的系统。
GainModeGainModeGainModeGainModegainModegain_mode 定义了估算时应采用固定卡尔曼增益,还是根据估算值与实际值的差异进行自适应增益调整。如果 GainModeGainModeGainModeGainModegainModegain_mode 设置为 'fixed'"fixed""fixed""fixed""fixed""fixed",则将
Gain1Gain1Gain1Gain1gain1gain_1 用作预测为前景像素的卡尔曼增益,Gain2Gain2Gain2Gain2gain2gain_2 用作预测为背景像素的增益。Gain1Gain1Gain1Gain1gain1gain_1 应小于 Gain2Gain2Gain2Gain2gain2gain_2,因为前景的自适应速度应慢于背景。Gain1Gain1Gain1Gain1gain1gain_1 和 Gain2Gain2Gain2Gain2gain2gain_2 均应小于 1.0。
如果 GainModeGainModeGainModeGainModegainModegain_mode 设置为 'frame'"frame""frame""frame""frame""frame",则会计算用于前景和背景估计的表格,其中包含所有 256 种可能灰度值变化的卡尔曼增益。此时Gain1Gain1Gain1Gain1gain1gain_1 和 Gain2Gain2Gain2Gain2gain2gain_2 分别表示适应估计值与实际值之间差异所需的帧数。因此,在固定适应时间(即帧数)下,所需卡尔曼增益随灰度值差异增大而增长。因此 Gain1Gain1Gain1Gain1gain1gain_1 应大于 Gain2Gain2Gain2Gain2gain2gain_2。当背景估计器用于生成“空场景”(假设观测区域始终存在移动对象)时,针对不同灰度值差异设置不同增益尤为重要。此时前景适应的适应时间(Gain1Gain1Gain1Gain1gain1gain_1)不可过长。Gain1Gain1Gain1Gain1gain1gain_1 和 Gain2Gain2Gain2Gain2gain2gain_2 均应大于
1.0。
AdaptModeAdaptModeAdaptModeAdaptModeadaptModeadapt_mode 表示用于估计值与实际值之间灰度值差异的前景/背景决策阈值是固定值,还是根据背景像素的灰度值偏差进行自适应调整。
如果 AdaptModeAdaptModeAdaptModeAdaptModeadaptModeadapt_mode 设置为 'off'"off""off""off""off""off",则参数
MinDiffMinDiffMinDiffMinDiffminDiffmin_diff 表示一个固定阈值。在此情况下,参数
StatNumStatNumStatNumStatNumstatNumstat_num、ConfidenceCConfidenceCConfidenceCConfidenceCconfidenceCconfidence_c 和 TimeCTimeCTimeCTimeCtimeCtime_c 均无意义。
如果 AdaptModeAdaptModeAdaptModeAdaptModeadaptModeadapt_mode 设置为 'on'"on""on""on""on""on",则
MinDiffMinDiffMinDiffMinDiffminDiffmin_diff 被解释为基础阈值。对于每个像素,会根据该像素值随时间变化的统计评估结果,向该阈值添加一个偏移量。StatNumStatNumStatNumStatNumstatNumstat_num 保存用于计算灰度值方差(FIR 滤波器)的数据集数量(过去帧数)。ConfidenceCConfidenceCConfidenceCConfidenceCconfidenceCconfidence_c 用于确定置信区间。
置信区间决定了背景像素被前景对象遮挡并被误判为前景时的背景统计值。根据学生 t-分布,置信常数为 4.30(3.25,2.82,2.26),对应 99,8% 置信区间(99,0%,98,0%,95,0%)。TimeCTimeCTimeCTimeCtimeCtime_c 参数用于控制指数函数的时间常数,该函数在像素被判定为前景时提升阈值。这意味着当前景区域检测到运动时,阈值将相应提高。此机制可容忍背景重新显现时更大幅度的光照变化。提高公差的主要原因在于:当背景被遮蔽时无法预测光照变化,因此无法对估计的背景图像进行适应性调整。
注意
如果 GainModeGainModeGainModeGainModegainModegain_mode 设置为 'frame'"frame""frame""frame""frame""frame",当 Gain1Gain1Gain1Gain1gain1gain_1 或 Gain2Gain2Gain2Gain2gain2gain_2 取较大值时,运行时间可能极其漫长,因为增益表的数值是通过简单的二分搜索确定的。
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
此算子返回一个句柄。请注意,即使该句柄被用作特定算子的输入参数,这些算子仍可能改变此句柄类型的实例状态。
参数
InitializeImageInitializeImageInitializeImageInitializeImageinitializeImageinitialize_image (输入对象) singlechannelimage → objectHImageHObjectHImageHobject (byte / real)
初始化图像。
Syspar1Syspar1Syspar1Syspar1syspar1syspar_1 (输入控制) real → HTuplefloatHTupleHtuple (real) (double) (double) (double)
1. 系统矩阵参数。
默认值:
0.7
建议值:
0.65, 0.7, 0.75
值范围:
0.05
≤
Syspar1
Syspar1
Syspar1
Syspar1
syspar1
syspar_1
≤
1.0
建议增量:
0.05
Syspar2Syspar2Syspar2Syspar2syspar2syspar_2 (输入控制) real → HTuplefloatHTupleHtuple (real) (double) (double) (double)
2. 系统矩阵参数。
默认值:
0.7
建议值:
0.65, 0.7, 0.75
值范围:
0.05
≤
Syspar2
Syspar2
Syspar2
Syspar2
syspar2
syspar_2
≤
1.0
建议增量:
0.05
GainModeGainModeGainModeGainModegainModegain_mode (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
增益类型。
默认值:
'fixed'
"fixed"
"fixed"
"fixed"
"fixed"
"fixed"
值列表:
'fixed'"fixed""fixed""fixed""fixed""fixed", 'frame'"frame""frame""frame""frame""frame"
Gain1Gain1Gain1Gain1gain1gain_1 (输入控制) real → HTuplefloatHTupleHtuple (real) (double) (double) (double)
卡尔曼增益/前景自适应时间。
默认值:
0.002
建议值:
10.0, 20.0, 50.0, 0.1, 0.05, 0.01, 0.005, 0.001
限制:
0.0 <= Gain1
Gain2Gain2Gain2Gain2gain2gain_2 (输入控制) real → HTuplefloatHTupleHtuple (real) (double) (double) (double)
卡尔曼增益/背景自适应时间。
默认值:
0.02
建议值:
2.0, 4.0, 8.0, 0.5, 0.1, 0.05, 0.01
限制:
0.0 <= Gain2
AdaptModeAdaptModeAdaptModeAdaptModeadaptModeadapt_mode (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
阈值自适应。
默认值:
'on'
"on"
"on"
"on"
"on"
"on"
值列表:
'off'"off""off""off""off""off", 'on'"on""on""on""on""on"
MinDiffMinDiffMinDiffMinDiffminDiffmin_diff (输入控制) real → HTuplefloatHTupleHtuple (real) (double) (double) (double)
前景/背景阈值。
默认值:
7.0
建议值:
3.0, 5.0, 7.0, 9.0, 11.0
建议增量:
0.2
StatNumStatNumStatNumStatNumstatNumstat_num (输入控制) integer → HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)
统计数据集的数量。
默认值:
10
建议值:
5, 10, 20, 30
值范围:
1
≤
StatNum
StatNum
StatNum
StatNum
statNum
stat_num
建议增量:
5
ConfidenceCConfidenceCConfidenceCConfidenceCconfidenceCconfidence_c (输入控制) real → HTuplefloatHTupleHtuple (real) (double) (double) (double)
置信常数。
默认值:
3.25
建议值:
4.30, 3.25, 2.82, 2.62
建议增量:
0.01
限制:
0.0 < ConfidenceC
TimeCTimeCTimeCTimeCtimeCtime_c (输入控制) real → HTuplefloatHTupleHtuple (real) (double) (double) (double)
衰减时间常数。
默认值:
15.0
建议值:
10.0, 15.0, 20.0
建议增量:
5.0
限制:
0.0 < TimeC
BgEstiHandleBgEstiHandleBgEstiHandleBgEstiHandlebgEstiHandlebg_esti_handle (输出控制) bg_estimation → HBgEsti, HTupleHHandleHTupleHtuple (handle) (IntPtr) (HHandle) (handle)
BgEsti 数据集的 ID。
示例(HDevelop)
* read Init-Image:
read_image (InitImage, 'xing/init')
* initialize 1. BgEsti-Dataset with
* fixed gains and threshold adaption:
create_bg_esti(InitImage,0.7,0.7,'fixed',0.002,0.02, \
'on',7.0,10,3.25,15.0,BgEstiHandle1)
* initialize 2. BgEsti-Dataset with
* frame orientated gains and fixed threshold
create_bg_esti(InitImage,0.7,0.7,'frame',30.0,4.0, \
'off',9.0,10,3.25,15.0,BgEstiHandle2)
结果
create_bg_esticreate_bg_estiCreateBgEstiCreateBgEstiCreateBgEsticreate_bg_esti 在所有参数正确时返回 2 (H_MSG_TRUE)。
可能的后继
run_bg_estirun_bg_estiRunBgEstiRunBgEstiRunBgEstirun_bg_esti
另见
set_bg_esti_paramsset_bg_esti_paramsSetBgEstiParamsSetBgEstiParamsSetBgEstiParamsset_bg_esti_params,
close_bg_esticlose_bg_estiCloseBgEstiCloseBgEstiCloseBgEsticlose_bg_esti
模块
基础