示例#1
0
    def write(self, results: Results, name: str):

        with results.write(name + ".txt") as fp:
            write_file(fp, self._regions)

        for k, v in self._properties.items():
            with results.write(name + "_" + k + ".value") as fp:
                fp.writelines([to_string(e) + "\n" for e in v])
示例#2
0
def write_sequence(directory: str, sequence: Sequence):

    channels = sequence.channels()

    metadata = dict()
    metadata["channel.default"] = sequence.metadata("channel.default", "color")
    metadata["fps"] = sequence.metadata("fps", "30")

    for channel in channels:
        cdir = os.path.join(directory, channel)
        os.makedirs(cdir, exist_ok=True)

        metadata["channels.%s" % channel] = os.path.join(channel, "%08d.jpg")

        for i in range(sequence.length):
            frame = sequence.frame(i).channel(channel)
            cv2.imwrite(os.path.join(cdir, "%08d.jpg" % (i + 1)),
                        cv2.cvtColor(frame, cv2.COLOR_RGB2BGR))

    for tag in sequence.tags():
        data = "\n".join([
            "1" if tag in sequence.tags(i) else "0"
            for i in range(sequence.length)
        ])
        with open(os.path.join(directory, "%s.tag" % tag), "w") as fp:
            fp.write(data)

    for value in sequence.values():
        data = "\n".join([
            str(sequence.values(i).get(value, ""))
            for i in range(sequence.length)
        ])
        with open(os.path.join(directory, "%s.value" % value), "w") as fp:
            fp.write(data)

    write_file(os.path.join(directory, "groundtruth.txt"),
               [f.groundtruth() for f in sequence])
    write_properties(os.path.join(directory, "sequence"), metadata)
示例#3
0
    def _generate(base, length, size):

        background_color = Image.fromarray(
            np.random.normal(15, 5, (size[1], size[0], 3)).astype(np.uint8))
        background_depth = Image.fromarray(
            np.ones((size[1], size[0]), dtype=np.uint8) * 200)
        background_ir = Image.fromarray(
            np.zeros((size[1], size[0]), dtype=np.uint8))

        template = Image.open(
            os.path.join(os.path.dirname(__file__), "cow.png"))

        dir_color = os.path.join(base, "color")
        dir_depth = os.path.join(base, "depth")
        dir_ir = os.path.join(base, "ir")

        os.makedirs(dir_color, exist_ok=True)
        os.makedirs(dir_depth, exist_ok=True)
        os.makedirs(dir_ir, exist_ok=True)

        path_color = os.path.join(dir_color, "%08d.jpg")
        path_depth = os.path.join(dir_depth, "%08d.png")
        path_ir = os.path.join(dir_ir, "%08d.png")

        groundtruth = []

        center_x = size[0] / 2
        center_y = size[1] / 2

        radius = min(center_x - template.size[0], center_y - template.size[1])

        speed = (math.pi * 2) / length

        for i in range(length):
            frame_color = background_color.copy()
            frame_depth = background_depth.copy()
            frame_ir = background_ir.copy()

            x = int(center_x + math.cos(i * speed) * radius -
                    template.size[0] / 2)
            y = int(center_y + math.sin(i * speed) * radius -
                    template.size[1] / 2)

            frame_color.paste(template, (x, y), template)
            frame_depth.paste(10, (x, y), template)
            frame_ir.paste(240, (x, y), template)

            frame_color.save(path_color % (i + 1))
            frame_depth.save(path_depth % (i + 1))
            frame_ir.save(path_ir % (i + 1))

            groundtruth.append(
                Rectangle(x, y, template.size[0], template.size[1]))

        write_file(os.path.join(base, "groundtruth.txt"), groundtruth)
        metadata = {
            "name": "dummy",
            "fps": 30,
            "format": "dummy",
            "channel.default": "color"
        }
        write_properties(os.path.join(base, "sequence"), metadata)