Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
haimat opened this issue Nov 3, 2021 · 14 comments · Fixed by #7697
Closed
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@haimat
Copy link

haimat commented Nov 3, 2021

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 haimat changed the title Feature Request - Allow to download annoated video frames as JPG images (instead of PNG) Feature Request - Allow to download annotated video frames as JPG images (instead of PNG) Nov 3, 2021
@nmanovic nmanovic added the enhancement New feature or request label Nov 7, 2021
@nmanovic
Copy link
Contributor

nmanovic commented Nov 7, 2021

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

@zhiltsov-max
Copy link
Contributor

zhiltsov-max commented Nov 28, 2021

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?

@haimat
Copy link
Author

haimat commented Nov 29, 2021

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
Copy link
Author

haimat commented Nov 21, 2022

@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?

@zhiltsov-max
Copy link
Contributor

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

@realtimshady1
Copy link

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

@zhiltsov-max
Copy link
Contributor

Hi, I think it could be supported fully when #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 zhiltsov-max added the good first issue Good for newcomers label Mar 19, 2024
@ChanBong
Copy link
Contributor

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

@ChanBong
Copy link
Contributor

ChanBong commented Mar 28, 2024

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
Copy link
Contributor

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 ?

@zhiltsov-max
Copy link
Contributor

zhiltsov-max commented Mar 28, 2024

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.

@ChanBong
Copy link
Contributor

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

@zhiltsov-max
Copy link
Contributor

zhiltsov-max commented Mar 29, 2024

@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.

@ChanBong
Copy link
Contributor

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

zhiltsov-max added a commit that referenced this issue Apr 10, 2024
#7697)

<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->

Allows to download annotated video frames with custom extensions.
Previously, it was only available in .png format. Resolves #3867

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- [ ] I have created a changelog fragment <!-- see top comment in
CHANGELOG.md -->
- [ ] I have updated the documentation accordingly
- [ ] I have added tests to cover my changes
- [x] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [x] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.

---------

Co-authored-by: Maxim Zhiltsov <zhiltsov.max35@gmail.com>
bargav25 pushed a commit to bargav25/cvat that referenced this issue Apr 10, 2024
cvat-ai#7697)

<!-- Raise an issue to propose your change
(https://github.com/opencv/cvat/issues).
It helps to avoid duplication of efforts from multiple independent
contributors.
Discuss your ideas with maintainers to be sure that changes will be
approved and merged.
Read the [Contribution
guide](https://opencv.github.io/cvat/docs/contributing/). -->

<!-- Provide a general summary of your changes in the Title above -->

### Motivation and context
<!-- Why is this change required? What problem does it solve? If it
fixes an open
issue, please link to the issue here. Describe your changes in detail,
add
screenshots. -->

Allows to download annotated video frames with custom extensions.
Previously, it was only available in .png format. Resolves cvat-ai#3867

### Checklist
<!-- Go over all the following points, and put an `x` in all the boxes
that apply.
If an item isn't applicable for some reason, then ~~explicitly
strikethrough~~ the whole
line. If you don't do that, GitHub will show incorrect progress for the
pull request.
If you're unsure about any of these, don't hesitate to ask. We're here
to help! -->
- [x] I submit my changes into the `develop` branch
- [ ] I have created a changelog fragment <!-- see top comment in
CHANGELOG.md -->
- [ ] I have updated the documentation accordingly
- [ ] I have added tests to cover my changes
- [x] I have linked related issues (see [GitHub docs](

https://help.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword))
- [x] I have increased versions of npm packages if it is necessary

([cvat-canvas](https://github.com/opencv/cvat/tree/develop/cvat-canvas#versioning),

[cvat-core](https://github.com/opencv/cvat/tree/develop/cvat-core#versioning),

[cvat-data](https://github.com/opencv/cvat/tree/develop/cvat-data#versioning)
and

[cvat-ui](https://github.com/opencv/cvat/tree/develop/cvat-ui#versioning))

### License

- [x] I submit _my code changes_ under the same [MIT License](
https://github.com/opencv/cvat/blob/develop/LICENSE) that covers the
project.
  Feel free to contact the maintainers if that's a concern.

---------

Co-authored-by: Maxim Zhiltsov <zhiltsov.max35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants