Fix cv2.imwrite on non-ASCII paths (#7139)

* Fix imwrite on non-ASCII paths

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update general.py

* Update __init__.py

* Update __init__.py

* Update datasets.py

* Update hubconf.py

* Update detect.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update general.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <glenn.jocher@ultralytics.com>
This commit is contained in:
authored and GitHub committed 2022-03-25 13:25:30 +01:00
1 parent a0a4adf6de
commit d115bbf509
5 files changed
+21 -14

No files matched your search

+16 -1
View File
@@ -904,5 +904,20 @@ def increment_path(path, exist_ok=False, sep='', mkdir=False):
return path
# Variables
# OpenCV Chinese-friendly functions ------------------------------------------------------------------------------------
def imread(path):
return cv2.imdecode(np.fromfile(path, np.uint8), cv2.IMREAD_COLOR)
def imwrite(path, im):
try:
cv2.imencode(Path(path).suffix, im)[1].tofile(path)
return True
except Exception:
return False
cv2.imread, cv2.imwrite = imread, imwrite # redefine
# Variables ------------------------------------------------------------------------------------------------------------
NCOLS = 0 if is_docker() else shutil.get_terminal_size().columns # terminal window size for tqdm