From 1cec0185a1b3a46d3285ae99705b50206d06c4fe Mon Sep 17 00:00:00 2001 From: Glenn Jocher Date: Mon, 21 Aug 2023 23:41:11 +0200 Subject: [PATCH] Improve `check_imshow()` robustness (#4483) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- tests/test_python.py | 5 +++-- ultralytics/utils/checks.py | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/test_python.py b/tests/test_python.py index 68a8d990..fa81295f 100644 --- a/tests/test_python.py +++ b/tests/test_python.py @@ -311,14 +311,15 @@ def test_utils_init(): def test_utils_checks(): - from ultralytics.utils.checks import (check_imgsz, check_requirements, check_yolov5u_filename, git_describe, - print_args) + from ultralytics.utils.checks import (check_imgsz, check_imshow, check_requirements, check_yolov5u_filename, + git_describe, print_args) check_yolov5u_filename('yolov5n.pt') # check_imshow(warn=True) git_describe(ROOT) check_requirements() # check requirements.txt check_imgsz([600, 600], max_dim=1) + check_imshow() print_args() diff --git a/ultralytics/utils/checks.py b/ultralytics/utils/checks.py index 505abcd5..aa48430b 100644 --- a/ultralytics/utils/checks.py +++ b/ultralytics/utils/checks.py @@ -20,9 +20,9 @@ import requests import torch from matplotlib import font_manager -from ultralytics.utils import (ASSETS, AUTOINSTALL, LOGGER, ONLINE, ROOT, USER_CONFIG_DIR, ThreadingLocked, TryExcept, - clean_url, colorstr, downloads, emojis, is_colab, is_docker, is_jupyter, is_kaggle, - is_online, is_pip_package, url2file) +from ultralytics.utils import (ASSETS, AUTOINSTALL, LINUX, LOGGER, ONLINE, ROOT, USER_CONFIG_DIR, ThreadingLocked, + TryExcept, clean_url, colorstr, downloads, emojis, is_colab, is_docker, is_jupyter, + is_kaggle, is_online, is_pip_package, url2file) def is_ascii(s) -> bool: @@ -389,8 +389,9 @@ def check_yaml(file, suffix=('.yaml', '.yml'), hard=True): def check_imshow(warn=False): """Check if environment supports image displays.""" try: - assert not any((is_colab(), is_kaggle(), is_docker())) - cv2.imshow('test', np.zeros((1, 1, 3))) + if LINUX: + assert 'DISPLAY' in os.environ and not is_docker() and not is_colab() and not is_kaggle() + cv2.imshow('test', np.zeros((8, 8, 3), dtype=np.uint8)) # show a small 8-pixel image cv2.waitKey(1) cv2.destroyAllWindows() cv2.waitKey(1)