Deep-Live-Cam icon indicating copy to clipboard operation
Deep-Live-Cam copied to clipboard

Update __init__.py

Open KunjShah01 opened this issue 7 months ago • 3 comments

Issue: Global Override of cv2.imread and cv2.imwrite for Unicode Path Support

Description

The current implementation in modules/__init__.py globally overrides cv2.imread and cv2.imwrite to support Unicode file paths by using np.fromfile and np.tofile. While this enables reading and writing images with Unicode paths, it replaces the original OpenCV functions for the entire project, which may cause unexpected behavior in other modules or third-party libraries that rely on the standard cv2 API.

Expected Behavior

  • The codebase should support reading and writing images with Unicode file paths.
  • The solution should not globally override standard library functions unless absolutely necessary.
  • If overriding is required, it should be done in a controlled and well-documented manner.

Actual Behavior

  • cv2.imread and cv2.imwrite are overridden globally for all imports, which may break compatibility with other code or libraries.

Suggested Solution

  • Refactor the Unicode-supporting functions to be utility functions (e.g., imread_unicode, imwrite_unicode) and use them explicitly where needed, rather than overriding the global cv2 functions.
  • Alternatively, conditionally override only if Unicode support is detected as missing, and document the change clearly.

Summary by Sourcery

Modify image reading and writing functions to support Unicode file paths by creating utility functions and globally overriding OpenCV's imread and imwrite methods

New Features:

  • Add Unicode-compatible image reading function imread_unicode
  • Add Unicode-compatible image writing function imwrite_unicode

Enhancements:

  • Provide alternative implementation for handling file paths with non-ASCII characters
  • Enable reading and writing images with Unicode file paths

KunjShah01 avatar May 05 '25 13:05 KunjShah01