Пример #1
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_trajectory(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)
Пример #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 download(self, url, path="."):
        from vot.utilities.net import download_uncompress, download_json, get_base_url, join_url, NetworkException

        if os.path.splitext(url)[1] == '.zip':
            logger.info(
                'Downloading sequence bundle from "%s". This may take a while ...',
                url)

            try:
                download_uncompress(url, path)
            except NetworkException as e:
                raise DatasetException(
                    "Unable do download dataset bundle, Please try to download the bundle manually from {} and uncompress it to {}'"
                    .format(url, path))
            except IOError as e:
                raise DatasetException(
                    "Unable to extract dataset bundle, is the target directory writable and do you have enough space?"
                )

        else:

            meta = download_json(url)

            logger.info('Downloading sequence dataset "%s" with %s sequences.',
                        meta["name"], len(meta["sequences"]))

            base_url = get_base_url(url) + "/"

            with Progress("Donwloading", len(meta["sequences"])) as progress:
                for sequence in meta["sequences"]:
                    sequence_directory = os.path.join(path, sequence["name"])
                    os.makedirs(sequence_directory, exist_ok=True)

                    data = {
                        'name': sequence["name"],
                        'fps': sequence["fps"],
                        'format': 'default'
                    }

                    annotations_url = join_url(base_url,
                                               sequence["annotations"]["url"])

                    try:
                        download_uncompress(annotations_url,
                                            sequence_directory)
                    except NetworkException as e:
                        raise DatasetException(
                            "Unable do download annotations bundle")
                    except IOError as e:
                        raise DatasetException(
                            "Unable to extract annotations bundle, is the target directory writable and do you have enough space?"
                        )

                    for cname, channel in sequence["channels"].items():
                        channel_directory = os.path.join(
                            sequence_directory, cname)
                        os.makedirs(channel_directory, exist_ok=True)

                        channel_url = join_url(base_url, channel["url"])

                        try:
                            download_uncompress(channel_url, channel_directory)
                        except NetworkException as e:
                            raise DatasetException(
                                "Unable do download channel bundle")
                        except IOError as e:
                            raise DatasetException(
                                "Unable to extract channel bundle, is the target directory writable and do you have enough space?"
                            )

                        if "pattern" in channel:
                            data["channels." +
                                 cname] = cname + os.path.sep + channel[
                                     "pattern"]
                        else:
                            data["channels." + cname] = cname + os.path.sep

                    write_properties(
                        os.path.join(sequence_directory, 'sequence'), data)

                    progress.relative(1)

            with open(os.path.join(path, "list.txt"), "w") as fp:
                for sequence in meta["sequences"]:
                    fp.write('{}\n'.format(sequence["name"]))