Пример #1
0
    def getboxes(self,
                 interpolate=False,
                 bind=False,
                 label=False,
                 groundplane=False):
        result = [x.getbox() for x in self.boxes]
        result.sort(key=lambda x: x.frame)

        if groundplane:
            homography = None
            with open(
                    os.path.join(self.job.segment.video.homographylocation,
                                 "homography.npy"), "r") as f:
                homography = np.load(f)

            for i in range(len(result)):
                t = homography.dot(np.array([result[i].xbr, result[i].ybr, 1]))
                result[i].xbr = float(t[0]) / t[2]
                result[i].ybr = float(t[1]) / t[2]
                result[i].xtl = result[i].xbr - 5
                result[i].ytl = result[i].ybr - 5

        if interpolate:
            if not self.interpolatecache:
                self.interpolatecache = LinearFill(result)
            result = self.interpolatecache

        if bind:
            result = Path.bindattributes(self.attributes, result)

        if label:
            for box in result:
                box.attributes.insert(0, self.label.text)

        return result
Пример #2
0
    def getboxes(self, interpolate = False, bind = False, label = False):
        result = [x.getbox() for x in self.boxes]
        result.sort(key = lambda x: x.frame)
        if interpolate:
            if not self.interpolatecache:
                self.interpolatecache = LinearFill(result)
            result = self.interpolatecache

        if bind:
            result = Path.bindattributes(self.attributes, result)

        if label:
            for box in result:
                box.attributes.insert(0, self.label.text)

        return result
Пример #3
0
def savejob(id, tracks):
    job = session.query(Job).get(id)

    # Update current job
    for path in job.paths:
        session.delete(path)
    session.commit()

    for path in readpaths(tracks):
        logger.info(path)
        job.paths.append(path)

    session.add(job)
    session.commit()

    # Update neigboring segments
    video = job.segment.video
    prevseg, nextseg = video.getsegmentneighbors(job.segment)

    mergesegments = [
        s for s in [prevseg, job.segment, nextseg] if s is not None
    ]
    updatesegments = [s for s in [prevseg, nextseg] if s is not None]

    # Create list of merged boxes with given label and userid
    labeledboxes = []
    for boxes, paths in merge.merge(mergesegments, threshold=0.8):
        path = paths[0]
        for p in paths:
            if p.job.segmentid == job.segmentid:
                path = p
                break
        labeledboxes.append((path.label, path.userid, boxes))

    # Remove paths in neighboring segments
    for segment in updatesegments:
        for path in segment.paths:
            session.delete(path)
    session.commit()

    # Add merged paths to neighboring segments
    for label, userid, boxes in labeledboxes:
        frames = sorted([box.frame for box in boxes])
        for segment in updatesegments:
            for job in segment.jobs:
                path = Path()
                path.label = label
                path.userid = userid
                addedbox = False
                for box in boxes:
                    if segment.start <= box.frame <= segment.stop:
                        newbox = Box(path=path)
                        newbox.frombox(box)
                        if not box.lost:
                            addedbox = True

                # Some segments and paths might not overlap
                if addedbox:
                    # Add in first frame if it's missing
                    if (frames[0] < segment.start < frames[-1]
                            and segment.start not in frames):
                        newbox = Box(path=path)
                        newbox.generated = False
                        newbox.frombox([
                            box for box in LinearFill(boxes)
                            if box.frame == segment.start
                        ][0])

                    job.paths.append(path)

                session.add(job)
    session.commit()