Python 未检测到任何对象时排序跟踪算法不起作用

Python 未检测到任何对象时排序跟踪算法不起作用,python,object-detection,video-tracking,Python,Object Detection,Video Tracking,我试图在我自己的自定义对象检测器上实现排序算法,但在空检测的情况下,我遇到了一些问题(因为初始帧还没有对象) 我已从中克隆了原始排序存储库 这是引发错误的代码(来自sort.py): 有什么可能的错误或者如何克服这个问题,我一直试图在没有检测到的情况下不进行更新,但这样做我无法估计新的位置 注释还指出,即使没有检测,也必须调用update 非常感谢您的帮助。我不知道这是否有帮助。 其中一个解决方法是使用这个方法,你称之为跟踪器。但跟踪ID将不断更新。创建单独的轨迹ID函数以获得平滑的轨迹更改

我试图在我自己的自定义对象检测器上实现排序算法,但在空检测的情况下,我遇到了一些问题(因为初始帧还没有对象)

我已从中克隆了原始排序存储库

这是引发错误的代码(来自sort.py):

有什么可能的错误或者如何克服这个问题,我一直试图在没有检测到的情况下不进行更新,但这样做我无法估计新的位置

注释还指出,即使没有检测,也必须调用update


非常感谢您的帮助。我不知道这是否有帮助。 其中一个解决方法是使用这个方法,你称之为跟踪器。但跟踪ID将不断更新。创建单独的轨迹ID函数以获得平滑的轨迹更改

       if box is not None:
            x, y, w, h = box
            detections = np.array([[x,y,w,h,score]])
            trackers = tracker.update(detections,infer_image)
            try:
                if len(trackers[0]>0):
                    print(trackers[0][4])
            except:
                print("nothing to track")

        else:
            detections = np.array([[0,0,0,0,0]])
            trackers = tracker.update(detections,infer_image)
再说一遍,这只是一种变通办法。为我所必须做的工作做得很好

更新: 替代解决方案:

    def convert_bbox_to_z(bbox):
  """
  Takes a bounding box in the form [x1,y1,x2,y2] and returns z in the form
    [x,y,s,r] where x,y is the centre of the box and s is the scale/area and r is
    the aspect ratio
  """
  w = bbox[2]-bbox[0]
  h = bbox[3]-bbox[1]
  x = bbox[0]+w/2.
  y = bbox[1]+h/2.
  s = w*h    #scale is just area
  r = w/float(h)
  return np.array([x,y,s,r]).reshape((4,1))

def convert_x_to_bbox(x,score=None):
  """
  Takes a bounding box in the centre form [x,y,s,r] and returns it in the form
    [x1,y1,x2,y2] where x1,y1 is the top left and x2,y2 is the bottom right
  """
  w = np.sqrt(x[2]*x[3])
  h = x[2]/w
  if(score==None):
    return np.array([x[0]-w/2.,x[1]-h/2.,x[0]+w/2.,x[1]+h/2.]).reshape((1,4))
  else:
    return np.array([x[0]-w/2.,x[1]-h/2.,x[0]+w/2.,x[1]+h/2.,score]).reshape((1,5))
       if box is not None:
            x, y, w, h = box
            detections = np.array([[x,y,w,h,score]])
            trackers = tracker.update(detections,infer_image)
            try:
                if len(trackers[0]>0):
                    print(trackers[0][4])
            except:
                print("nothing to track")

        else:
            detections = np.array([[0,0,0,0,0]])
            trackers = tracker.update(detections,infer_image)