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

Installation/import problem -- 'xfeatures2d module is not available' #112

Open
stevenjayfrank opened this issue Apr 3, 2024 Discussed in #111 · 7 comments
Open

Installation/import problem -- 'xfeatures2d module is not available' #112

stevenjayfrank opened this issue Apr 3, 2024 Discussed in #111 · 7 comments

Comments

@stevenjayfrank
Copy link

Discussed in #111

Originally posted by stevenjayfrank April 3, 2024
I've hit a dead end attempting to import Valis following installation. Importing results in an AttributeError: module 'cv2' has no attribute 'xfeatures2d'. This is not a new problem and the most common solution is to install opencv-contrib-python rather than opencv-python. Unfortunately the xfeatures2d seems to be unavailable in any opencv distribution compatible with current (or even recent) version of Python. I've tried installing under Windows 11 (which had even more problems) and Linux. Suggestions appreciated.

@cdgatenbee
Copy link
Collaborator

Hi @stevenjayfrank,
I think there are probably a few quick solution options here. One would be to create a new virtual environment that uses a version of Python that is compatible with a opencv-contrib-python (or opencv-contrib-python-headless, which is what is in the pyproject.toml) that has xfeatures2d (at least Python 3.8-3.11, but not sure about >= 3.12) and then install valis using pip inside that virtual environment. A second might be to try using the Docker container. Unfortunately, the default feature detectors and descriptors are from xfeatures2d, so I may look into replacing them, but finding suitable replacements may take some time. In the meantime, please try one of the other options and let me know how it goes.

Best,
-Chandler

@stevenjayfrank
Copy link
Author

stevenjayfrank commented Apr 4, 2024

Thanks for replying, Chandler! I generally use Python 3.11 but have also tried 3.10, and have installed opencv-contrib-python as well as opencv-contrib-python-headless and plain old opencv-python, followed by reinstallation of valis each time. None of the opencv versions I've used seems to contain xfeatures2d. All are based on opencv version 4.9.0.80. Could you tell me which version of opencv you're using successfully?

This StackExchange post reports that xfeatures2d works only on opencv versions 3.3.0.10 or earlier, and those are no longer available for installation with pip. I also tried cloning from https://github.com/opencv/opencv_contrib.git, which does contain the xfeatures2d function, but you can't install directly from the git -- you have to use CMake, and while I was able to make the build, I still haven't been able to make it visible to Python.

@cdgatenbee
Copy link
Collaborator

Hi @stevenjayfrank,
It looks like the version of opencv-contrib-python-headless I've been using is also 4.9.0.80, so I'm not entirely what's going on. Could you try creating an environment using the poetry.lock file? You can also check out the pyproject.toml, which can be found here, but you'll probably want to edit the info in the [tool.poetry] section, and remove line 8 (packages = [{include = "valis"}]), which looks for valis locally. Creating the environment this way does require installing poetry, but the lock file has the exact ("pinned") versions of each package for each OS. That lock file is used to create the virtual environments during testing, and many tests involve importing xfeatures2d. Testing is done locally on M1 mac, as well as on Ubuntu, Windows, and Intel Mac OS when the code gets pushed to github. All that to say that the lock file has been tested on different OS with Python 3.9-3.11, and so should create a virtual environment that includes xfeatures2d. Please try that out and let me know how it goes.

Best,
-Chandler

@stevenjayfrank
Copy link
Author

stevenjayfrank commented Apr 5, 2024

Thank you, I will try that. In the meantime, I've been thinking maybe it's an Anaconda issue, so tried installing valis using PyCharm with Python 3.11 under Windows 11. Installation using pip install valis-wsi or pip install git+https://github.com/MathOnco/valis.git nearly completes, but fails at the end when attempting to build a wheel for scikit-image -- even when scikit-image has previously been installed.

To exhaust the obvious alternatives, I installed valis directly from a Windows terminal. The installation was successful, but attempting to import in Python threw this error:

OSError: cannot load library 'libgobject-2.0-0.dll': error 0x7e. Additionally, ctypes.util.find_library() did not manage to locate a library called 'libgobject-2.0-0.dll'

@stevenjayfrank
Copy link
Author

stevenjayfrank commented Apr 6, 2024

I'm new to Poetry but have given it a whirl in Linux, and created a new project called poetry-valis. I don't know how to create an environment solely from the poetry.lock file, so I included your pyproject.toml file with line 8 removed, and ran install. Everything seems to have installed correctly, and I activated the environment with source $(poetry env info --path)/bin/activate.

If I now run Python or Jupyter Lab from within the environment (e.g., poetry run python), there's no valis package to import. In fact, if I list packages with poetry show, there are many installed packages but valis isn't among them. The statement registrar = registration.Valis(slide_src_dir, results_dst_dir) throws NameError: name 'registration' is not defined.

I'm probably missing something really obvious ...

@cdgatenbee
Copy link
Collaborator

Hi @stevenjayfrank,
Sorry about that, I guess I my response had focused mainly on creating an environment that has opencv with xfeatures2d. To add valis to the environment, move to the directory that has the pyproject.toml and run poetry add valis-wsi in the terminal. That should install valis to the environment and also update poetry.lock and pyproject.toml. Please try that out and let me know how it goes.

Best,
-Chandler

@stevenjayfrank
Copy link
Author

Thanks, Chandler, got it working (also needed to run poetry update) -- really appreciate your help! Fantastic capabilities and extremely well documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants