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

[Environment] OpenCV NULL guiReceiver error during pre-commit testing . #230

Open
Drita-ai opened this issue Oct 6, 2024 · 4 comments
Open
Labels
bug Something isn't working Easy good first issue Good for newcomers hacktoberfest up-for-grabs

Comments

@Drita-ai
Copy link

Drita-ai commented Oct 6, 2024

Describe the bug
While running pre-commit hooks and pytest for my application, I'm encountering an OpenCV error related to GUI functions.

To Reproduce
Steps to reproduce the behavior:

  1. Make any changes in code.
  2. Run commands git add and pre-commit run -a (make sure pre-commit is installed).
  3. Commit changes by running git commit -m "commit message"

Screenshots
Screenshot from 2024-10-03 20-23-30

Desktop (please complete the following information):

  • OS: Ubuntu 24.04.1 LTS
  • Python version - 3.12.3
  • OpenCV version - 4.10.0
@Drita-ai
Copy link
Author

Drita-ai commented Oct 6, 2024

This error is related to OpenCV's highgui module which is responsible for creating windows. This error often occurs when OpenCV functions that require a GUI (like cv2.imshow(), cv2.moveWindow(), etc.) are called, but the environment where the code is running doesn't support GUI display (e.g., a headless server or during testing).

In the context of running tests with pytest and pre-commit hooks, we likely don't need the GUI features.

Solution
So, pip install opencv-python-headless install the headless version of OpenCV, which excludes GUI functionality and this prevents OpenCV from trying to use any GUI functions.

@Udayraj123
Copy link
Owner

Udayraj123 commented Oct 7, 2024

@Drita-ai Thanks for reporting!

I think using headless python shouldn't be the default way but we should definitely check if the monitor or windows are available before imshow() and moveWindow() are called in the show() function

@Princekumarofficial
Copy link

@Udayraj123 Added a PR for the same #231

@Udayraj123
Copy link
Owner

@Drita-ai can you verify if this solves the issue for you?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Easy good first issue Good for newcomers hacktoberfest up-for-grabs
Projects
None yet
Development

No branches or pull requests

3 participants