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

Support Multilanguage for imread and imwrite #2103

Merged

Conversation

developer0hye
Copy link
Contributor

@developer0hye developer0hye commented Apr 18, 2023

πŸ€– Generated by Copilot at 0bacaa3

Summary

πŸ“·πŸŒπŸ˜Š

Added imread and imwrite functions to handle filenames with emojis or non-ASCII characters in ultralytics/yolo/utils/__init__.py. Redefined cv2 functions to use the new wrappers for better compatibility and robustness.

imread, imwrite
wrap OpenCV functions
autumn of emojis

Walkthrough

  • Define new functions imread and imwrite to handle filenames with emojis or non-ASCII characters (link)
  • Redefine OpenCV functions cv2.imread and cv2.imwrite to use the new wrappers (link)

πŸ› οΈ PR Summary

Made with ❀️ by Ultralytics Actions

🌟 Summary

Enhancement of OpenCV functions to support multilingual file paths.

πŸ“Š Key Changes

  • Added a custom imread function to handle reading images using file paths with non-ASCII characters.
  • Implemented a custom imwrite function that ensures images are saved to paths containing multilingual characters.
  • Upgraded the imshow function to correctly display window titles with non-ASCII characters.

🎯 Purpose & Impact

  • Purpose: To overcome issues with OpenCV's standard functions that struggle with file paths containing non-ASCII, especially multilingual characters.
  • Impact: These changes will allow Ultralytics users with multilingual environments to read, write, and display images without encountering errors due to path encoding issues. This makes their tools more accessible globally. 🌍✨

@glenn-jocher
Copy link
Member

@developer0hye great idea, thanks for the PR!

I've updated the implementation to match YOLOv5.

@glenn-jocher glenn-jocher changed the base branch from main to updates April 19, 2023 17:51
@glenn-jocher glenn-jocher merged commit de71ba9 into ultralytics:updates Apr 19, 2023
1 check passed
@developer0hye developer0hye deleted the multilanguage-opencv-functions branch April 19, 2023 21:32
@developer0hye
Copy link
Contributor Author

developer0hye commented Apr 20, 2023

@glenn-jocher Jocher, I couldn't load an image file whose path contains Korean with the modified code.

my command: yolo train task=detect model=yolov8n.yaml pretrained=yolov8n.pt epochs=300 workers=0

image

Path(inspect.stack()[0].filename).parent.parent.as_posix() in inspect.stack()[-1].filename returns False

image

image

image

@glenn-jocher
Copy link
Member

Hello @developer0hye, sorry to hear that you are experiencing issues with file paths containing Korean characters. It looks like you provided some screenshots, which is a great way to help identify the issue. It seems that the Path method is failing to identify the correct path, resulting in the error you encountered. Can you confirm that the file exists in the provided path, and that you are using the correct path syntax? If you continue to encounter issues, please let me know and we can investigate further. Additionally, feel free to refer to our documentation at https://docs.ultralytics.com for more information on file handling with YOLOv8.

@developer0hye
Copy link
Contributor Author

developer0hye commented Apr 20, 2023

@glenn-jocher Thanks for reviewing it!

I confirmed that the file existed in the provided path. I think that I am using the correct path syntax.

@glenn-jocher
Copy link
Member

@developer0hye, thanks for confirming that the file exists in the provided path, and it sounds like the path syntax is correct. It's possible that the issue might be related to how Python is interpreting the Korean characters in the file path. I would recommend trying to use the unicode escape sequence for the Korean characters in the file path, which should help Python recognize the path correctly. You can refer to our documentation at https://docs.ultralytics.com for more information on how to handle unicode characters in file paths.

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.

None yet

2 participants