lap.lapjv函数cost_limit参数

查了不少资料,最后还是看函数文档看懂了。

cost_limit 是代价矩阵中每个元素的上限值,超过cost_limit的元素就不参与分配了。

Docstring:
Solve linear assignment problem using Jonker-Volgenant algorithm.

cost: an N x N matrix containing the assignment costs. Entry cost[i, j] is
  the cost of assigning row i to column j.
extend_cost: whether or not extend a non-square matrix [default: False]
cost_limit: an upper limit for a cost of a single assignment
            [default: np.inf]
return_cost: whether or not to return the assignment cost

Returns (opt, x, y) where:
  opt: cost of the assignment, not returned if return_cost is False.
  x: a size-N array specifying to which column each row is assigned.
  y: a size-N array specifying to which row each column is assigned.

When extend_cost and/or cost_limit is set, all unmatched entries will be
marked by -1 in x/y.
Type:      builtin_function_or_method

用视频跟踪举个例子:

如图为kilman预测和检测框计算出来的代价矩阵,一般计算方式为1-iou。

然后把代价矩阵送入lapjv,以总体最小代价(分配后元素和最小)实现任务分配。

K1K2K3
D1

0.5

0.60.7
D20.40.70.5
from lap import lapjv
import numpy as np

a = np.array([[0.5,0.6,0.7],[0.4,0.7,0.5]])
 
c,x,y = lapjv(a,extend_cost=True,cost_limit=0.4)
 
print(c,x,y)

output:0.4 [-1  0] [ 1 -1 -1]

c为求得的最小代价之和,x和y为分配结果,一个是将y分配给x,一个是将x分配个y,是一样的; 以x为例,-1代表未被匹配。 所以[-1,0]代表D1没有匹配项,D2匹配到了K1; cost_limit为代价矩阵中每个元素可以取值的上限不能超过0.4。

cost_limit改为0.6看一下:

from lap import lapjv
import numpy as np

a = np.array([[0.5,0.6,0.7],[0.4,0.7,0.5]])
 
c,x,y = lapjv(a,extend_cost=True,cost_limit=0.6)
 
print(c,x,y)

output: 1.0 [0 2] [ 0 -1  1]

这回两个目标都匹配上了,x=[0,2]代表D1匹配了K1,D2匹配了K3。

在目标跟踪里, cost_limit设置过小,会漏掉能匹配上的目标,设置过大,会增加错误的匹配。

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值