问题描述
我正在使用SORT算法的开源版本https://github.com/abewley/sort来跟踪mp4视频上的对象。
我在sort.py
中遇到了与此功能有关的问题
def associate_detections_to_trackers(detections,trackers,IoU_threshold=0.3):
"""
Assigns detections to tracked object (both represented as bounding Boxes)
Returns 3 lists of matches,unmatched_detections and unmatched_trackers
"""
if (len(trackers) == 0):
return np.empty((0,2),dtype=int),np.arange(len(detections)),np.empty((0,5),dtype=int)
IoU_matrix = np.zeros((len(detections),len(trackers)),dtype=np.float32)
for d,det in enumerate(detections):
for t,trk in enumerate(trackers):
IoU_matrix[d,t] = IoU(det,trk)
matched_indices = linear_assignment(-IoU_matrix)
unmatched_detections = []
for d,det in enumerate(detections):
if (d not in matched_indices[0]):
unmatched_detections.append(d)
unmatched_trackers = []
for t,trk in enumerate(trackers):
if (t not in matched_indices[1]):
unmatched_trackers.append(t)
# filter out matched with low IoU
matches = []
for m in matched_indices:
if (IoU_matrix[m[0],m[1]] < IoU_threshold):
unmatched_detections.append(m[0])
unmatched_trackers.append(m[1])
else:
#THIS LINE
matches.append(m.reshape(1,2))
if (len(matches) == 0):
matches = np.empty((0,dtype=int)
else:
matches = np.concatenate(matches,axis=0)
return matches,np.array(unmatched_detections),np.array(unmatched_trackers)
我遇到以下错误ValueError: cannot reshape array of size 14 into shape (1,2)
。将匹配的索引附加到匹配的数组时,会发生这种情况。我知道为什么会发生这种情况,但是我不明白为什么作者将数组改形为1、2,因为匹配索引的大小未知?由于我不熟悉状态估计算法或数据关联,因此在调试该程序并真正了解该算法的功能时遇到了问题。有什么建议吗?
我要适应的项目在这里https://github.com/sftwre/ObjectDetection。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)