Fix `detect.py --view-img` for non-ASCII paths (#7093)
Browse files* Update detect.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update general.py
* Update detect.py
* Update general.py
* Update general.py
* Update general.py
* Update general.py
* Update general.py
* Update general.py
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Update general.py
* Update general.py
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Glenn Jocher <[email protected]>
- utils/general.py +8 -1
utils/general.py
CHANGED
@@ -905,6 +905,9 @@ def increment_path(path, exist_ok=False, sep='', mkdir=False):
|
|
905 |
|
906 |
|
907 |
# OpenCV Chinese-friendly functions ------------------------------------------------------------------------------------
|
|
|
|
|
|
|
908 |
def imread(path):
|
909 |
return cv2.imdecode(np.fromfile(path, np.uint8), cv2.IMREAD_COLOR)
|
910 |
|
@@ -917,7 +920,11 @@ def imwrite(path, im):
|
|
917 |
return False
|
918 |
|
919 |
|
920 |
-
|
|
|
|
|
|
|
|
|
921 |
|
922 |
# Variables ------------------------------------------------------------------------------------------------------------
|
923 |
NCOLS = 0 if is_docker() else shutil.get_terminal_size().columns # terminal window size for tqdm
|
|
|
905 |
|
906 |
|
907 |
# OpenCV Chinese-friendly functions ------------------------------------------------------------------------------------
|
908 |
+
imshow_ = cv2.imshow # copy to avoid recursion errors
|
909 |
+
|
910 |
+
|
911 |
def imread(path):
|
912 |
return cv2.imdecode(np.fromfile(path, np.uint8), cv2.IMREAD_COLOR)
|
913 |
|
|
|
920 |
return False
|
921 |
|
922 |
|
923 |
+
def imshow(path, im):
|
924 |
+
imshow_(path.encode('unicode_escape').decode(), im)
|
925 |
+
|
926 |
+
|
927 |
+
cv2.imread, cv2.imwrite, cv2.imshow = imread, imwrite, imshow # redefine
|
928 |
|
929 |
# Variables ------------------------------------------------------------------------------------------------------------
|
930 |
NCOLS = 0 if is_docker() else shutil.get_terminal_size().columns # terminal window size for tqdm
|