cvat icon indicating copy to clipboard operation
cvat copied to clipboard

Feature Request - Allow to download annotated video frames as JPG images (instead of PNG)

Open haimat opened this issue 3 years ago • 5 comments

Hello everyone, I have a question regarding the "export dataset" feature in CVAT. When I use it and select the "save images" option, then all video frames will be downloaded as PNG images. Is there a way to tell CVAT that I would rather download all those images as JPG files?

If that is not an option currently, is there any chance you could add such an option in a future release? I understand that you might want to provide lossless images for video frames, but that might not be necessary in all cases.

Thanks for your consideration.

haimat avatar Nov 03 '21 21:11 haimat

@haimat , thanks for the report. I agree that it is an important feature which should be implemented.

nmanovic avatar Nov 07 '21 16:11 nmanovic

You can export in any desired dataset format and convert images using Datumaro:

pip install datumaro[default]
datum convert -i dataset/path/ -if <input_format> -o output/path/ -f <input_format> -- --save-images --image-ext=jpg

Maybe, we could extend the CLI script with an option to save images in some other format?

zhiltsov-max avatar Nov 28 '21 10:11 zhiltsov-max

You can export in any desired dataset format and convert images using Datumaro:

I know that I can convert the images after downloading them. But the thing is their size - downloading all frames from a video as PNGs often leads to a 10gb+ zip archive. However, after converting them to JPGs they have about 1gb or even less as zip archive. And in my case I don't need PNGs, as we work with JPGs anyway ...

haimat avatar Nov 29 '21 08:11 haimat

@nmanovic Any update on this? If we would like to implement that on our own in CVAT, where would we want to look for that in the CVAT sources?

haimat avatar Nov 21 '22 19:11 haimat

Hi, no, no updates yet. Please check this code fragment: https://github.com/opencv/cvat/blob/develop/cvat-sdk/cvat_sdk/core/proxies/tasks.py#L138-L184

zhiltsov-max avatar Nov 22 '22 15:11 zhiltsov-max

Hi any update on this? My team too would also love if this were to be implemented as it would save us a lot of time and resource in post-processing

realtimshady1 avatar May 08 '23 01:05 realtimshady1

Hi, I think it could be supported fully when https://github.com/opencv/cvat/issues/1804 is addressed. However, at the moment we can easily support frame downloading with custom extension in the CLI/SDK "download frames" functionality.

zhiltsov-max avatar Mar 19 '24 11:03 zhiltsov-max

@nmanovic I am interested in solving this issue. Please assign it to me.

ChanBong avatar Mar 28 '24 13:03 ChanBong

Plan to fix:

  • pass an additonal argument to the CLI/SDK "download frames" function in the form of image_extension. Then, instead of inferring the extension from the MIME type, we can directly use the provided extension and download the file as such
    def download_frames(
        self,
        frame_ids: Sequence[int],
        image_extension: str,
        *,
        outdir: str = ".",
        quality: str = "original",
        filename_pattern: str = "frame_{frame_id:06d}{frame_ext}",
    ) -> Optional[List[Image.Image]]:
        """
        Download the requested frame numbers for a job and save images as outdir/filename_pattern
        """

        outdir = Path(outdir)
        outdir.mkdir(parents=True, exist_ok=True)

        for frame_id in frame_ids:
            frame_bytes = self.get_frame(frame_id, quality=quality)

            im = Image.open(frame_bytes)
            im_ext = f".{image_extension.strip('.')}"

            outfile = filename_pattern.format(frame_id=frame_id, frame_ext=im_ext)
            im.save(outdir / outfile)

ChanBong avatar Mar 28 '24 16:03 ChanBong

To add an extra typesafe, we can only allow a limited number of extensions. Maybe add a dropdown menu in the UI to select the image extension ?

ChanBong avatar Mar 28 '24 16:03 ChanBong

Looks good to me.

To add an extra typesafe, we can only allow a limited number of extensions.

If you want, it can be checked, but basically, you'll rely on what's provided by the underlying library, OpenCV or Pillow.

Maybe add a dropdown menu in the UI to select the image extension ?

Which UI? It's SDK and a CLI tool.

zhiltsov-max avatar Mar 28 '24 17:03 zhiltsov-max

If you want, it can be checked, but basically, you'll rely on what's provided by the underlying library, OpenCV or Pillow.

makes sense. I'll go forward with this only then.

Which UI? It's SDK and a CLI tool.

Oh ! Nevermind then. I meant having a dropdown menu here, just below the save images toggle image

ChanBong avatar Mar 28 '24 17:03 ChanBong

@ChanBong,

Maybe add a dropdown menu in the UI to select the image extension ?

Speaking about the full solution - yes, that's how it should be done. This will require adding this option in UI, changing server API for dataset export, and forwarding the parameters passed in the endpoint to the dataset exporter. The recoding itself will be done by Datumaro, it should not be a problem. We're welcome you to continue with such implementation, if you feel you can do this.

zhiltsov-max avatar Mar 29 '24 13:03 zhiltsov-max

Yeah. That would be perfect. I will continue with this as soon as the proposal period is over

ChanBong avatar Mar 29 '24 13:03 ChanBong