Пример #1
0
def meanshift(start, stop, framepoints, initialrect, imagesize, iterations=5):
    boxes = {}
    rect = initialrect
    inc = 1 if start <= stop else -1
    for frame in range(start, stop, inc):
        if frame not in framepoints:
            continue
        haspoints = True
        rect = rectforpoints(framepoints[frame], rect, iterations)

        # If we updated the rect save it and continue to the next frame
        # otherwise mark as lost
        if haspoints and insideframe(rect, imagesize):
            boxes[frame] = vision.Box(max(0, rect[0]),
                                      max(0, rect[1]),
                                      min(imagesize[1],
                                          rect[0] + initialrect[2]),
                                      min(imagesize[0],
                                          rect[1] + initialrect[3]),
                                      frame=frame,
                                      generated=True)
        else:
            print "Frame {0} lost in {1} to {2}".format(frame, start, stop)
            boxes[frame] = vision.Box(max(0, rect[0]),
                                      max(0, rect[1]),
                                      min(imagesize[1],
                                          rect[0] + initialrect[2]),
                                      min(imagesize[0],
                                          rect[1] + initialrect[3]),
                                      frame=frame,
                                      lost=True,
                                      generated=True)
            break
    return boxes
Пример #2
0
 def getbox(image, frame = None):
     if frame:
         box = vision.Box(*getcoords(image[frame]))
         box.frame = frame
         return box
     else:
         return vision.Box(*getcoords(image))
 def dbox_to_visbox(dbox, frame):
     """
     def __init__(self, int xtl, int ytl, int xbr, int ybr,
              int frame = 0, int lost = 0, int occluded = 0,
              image = None, label = None,
              int generated = 0, double score = 0.0, attributes = None):
     """
     visbox = vision.Box(dbox.left(), dbox.top(), dbox.left(), dbox.bottom(), frame=frame)
     return visbox
Пример #4
0
 def getbox(self):
     return vision.Box(self.xtl,
                       self.ytl,
                       self.xbr,
                       self.ybr,
                       self.frame,
                       self.outside,
                       self.occluded,
                       0,
                       generated=self.generated)
Пример #5
0
 def getbox(self):
     vb = vision.Box(self.xtl,
                     self.ytl,
                     self.xbr,
                     self.ybr,
                     self.frame,
                     self.outside,
                     self.occluded,
                     0,
                     generated=self.generated)
     #        print 'frame id: {}, generated: {}'.format(vb.frame, vb.generated)
     return vb
Пример #6
0
def boxforpoints(points, width, height, imagesize, frame):
    m = np.mean(np.array(points), axis=0)
    rect = (m[0] - (0.5 * width), m[1] - (0.5 * height), width, height)
    rect = rectforpoints(points, rect)
    print imagesize
    print rect
    return vision.Box(max(0, rect[0]),
                      max(0, rect[1]),
                      min(imagesize[1], rect[0] + rect[2]),
                      min(imagesize[0], rect[1] + rect[3]),
                      frame=frame,
                      generated=True)
 def dlib_track(self, start, stop, frames, initialrect, imagesize):
     #print "Starting tracking again!"
     boxes = {}
     #points = self.tracker.get_position()
     rect = initialrect#points_to_visbox(points, start)
     inc = 1 if start <= stop else -1
     occluded = 0
     for frame in range(start, stop, inc):
         frame1 = 0
         track_score = self.tracker.update(frames[frame].astype(np.uint8))/100.0
         #print "Score: %f"%(track_score/100.0)
         rect = self.tracker.get_position()
         #print rect
         # If we updated the rect save it and continue to the next frame
         # Otherwise, if the tracking score is too low, call the face occluded and stop
         # Otherwise mark as lost
         
         if not self.insideframe(rect, imagesize):
             
             print "Frame {0} lost in {1} to {2}".format(frame, start, stop)
             
             # make sure bbox is within bounds of the image and all corners
             # are where they should be relative to each other
             xtl = max(0, rect[0])
             ytl = max(0, rect[1])
             xbr = max(min(imagesize[1], rect[0] + initialrect[2]), xtl+1)
             ybr = max(min(imagesize[0], rect[1] + initialrect[3]), ytl+1)
             #print((xtl, ytl, xbr, ybr))
             boxes[frame] = vision.Box(
                 xtl,
                 ytl,
                 xbr,
                 ybr,
                 frame=frame,
                 #lost=True,
                 generated=True,
                 score=track_score
             )
             #break
             """
             print("RECT")
             print(rect)
             print("IMAGESIZE")
             print(imagesize)
             print("INITIALRECT")
             print(initialrect)
             print "May have gone off frame"
             """
         else:
             '''
             if track_score < TRACKING_THRESHOLD:
                 print("Frame {0} occluded in {1} to {2} with score {3}".format(frame, start, stop, track_score))
                 occluded += 1
                 frame1 = frame
                 boxes[frame] = vision.Box(
                     max(0, rect[0]),
                     max(0, rect[1]),
                     min(imagesize[1], rect[0] + initialrect[2]),
                     min(imagesize[0], rect[1] + initialrect[3]),
                     frame=frame,
                     #lost=True,
                     generated=True,
                     occluded=True,
                     score=track_score
                     #attributes=['Occluded']
                 )
             else:
                 frame2 = frame
                 if frame1 == frame2:
                     print("Something isn't right...")
             '''
             
             boxes[frame] = vision.Box(
                 max(0, rect[0]),
                 max(0, rect[1]),
                 min(imagesize[1], rect[0] + initialrect[2]),
                 min(imagesize[0], rect[1] + initialrect[3]),
                 frame=frame,
                 generated=True,
                 score=track_score
             )
 
     #print(occluded)
     
     return boxes
 def points_to_visbox(self, points, frame):
     """
     """
     return vision.Box(points[0], points[1], points[2], points[3], frame=frame)