Skip to content

Fixed Saving images with OpenCV #2772

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

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

RunDevelopment
Copy link
Member

@RunDevelopment RunDevelopment commented Apr 9, 2024

While working on #1612, I noticed that save images with OpenCV was broken. I fixed the following:

  • Saving images with invalid ASCII file names would either silently fail (e.g. *) or crash the backend (e.g. %$). I fixed this by using the same code path for both ASCII and non-ASCII file paths.
  • Overwriting images with non-ASCII file paths didn't work properly. The issue was os.rename doesn't work when the file already exists.

The solution for both problems is to (1) cv2.imencode and (2) save the buffer with regular open. This is simple and works correctly. The only issue is that it's a tiny bit slower for very large files, but that's a reasonable price to pay for correctness.


I also checked saving images with PIL and the DDS stuff. Both work correctly.

@joeyballentine joeyballentine merged commit 1717923 into chaiNNer-org:main Apr 9, 2024
@RunDevelopment RunDevelopment deleted the fix-save-cv branch April 9, 2024 13:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants