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

About packages #896

Closed
eishwezin20 opened this issue Sep 3, 2023 · 8 comments
Closed

About packages #896

eishwezin20 opened this issue Sep 3, 2023 · 8 comments

Comments

@eishwezin20
Copy link

Can anyone explain me comparism of pip install opencv
vs pip install opencv-contrib-python

@Mattral
Copy link

Mattral commented Sep 3, 2023

pip install opencv and pip install opencv-contrib-python are two different ways to install OpenCV (Open Source Computer Vision Library) in Python, and they provide slightly different functionality and packages.

  1. pip install opencv:

    • This command installs the main OpenCV package for Python.
    • It includes the core functionality of OpenCV, which allows you to perform basic computer vision tasks like image and video manipulation, object detection, and image processing.
    • This version typically includes stable and well-documented features, making it suitable for most common computer vision applications.
  2. pip install opencv-contrib-python:

    • This command installs the "contrib" version of OpenCV for Python.
    • In addition to the core functionality of OpenCV, it includes extra modules and features contributed by the open-source community. These modules might include experimental or less stable features, but they can be powerful for specialized tasks.
    • The "contrib" version can be more up-to-date with the latest developments and features, but it may also be less stable or less well-documented than the main package.
    • It allows you to access a wider range of computer vision algorithms and tools, which can be beneficial for advanced or specialized projects.

In summary, the choice between pip install opencv and pip install opencv-contrib-python depends on your specific needs:

  • If you need the core functionality of OpenCV for common computer vision tasks, pip install opencv is a safe and widely used choice.
  • If you require additional, potentially more experimental, computer vision modules and features, or if you want to stay up-to-date with the latest developments in the OpenCV community, pip install opencv-contrib-python might be more suitable.

Consider your project requirements and the stability of the features you need when choosing between these two installation options.

@eishwezin20
Copy link
Author

Thanks

@daveisfera
Copy link

Would it be possible to have contrib be an extra? I have one dependency that uses opencv and one that uses contrib so I end up with two installed that conflict, but shouldn't contrib be a superset of the base package?

@Mattral
Copy link

Mattral commented Sep 30, 2023

As far as I understand,

The relationship between the base OpenCV package and the OpenCV-contrib-python package can sometimes lead to conflicts and confusion, but they serve different purposes:

  1. OpenCV (Base Package): The base OpenCV package contains the essential components and modules of the OpenCV library. It includes core computer vision functionality, such as image processing, feature detection, and camera calibration. This package is typically sufficient for most computer vision tasks.

  2. OpenCV-contrib-python (Contrib Package): The OpenCV-contrib-python package contains additional modules and functionalities contributed by the community but not included in the base package. These extra modules may include advanced computer vision algorithms, machine learning tools, and various experimental features.

The reason they are separate packages is to keep the core library lightweight and modular. However, it's possible to install both packages simultaneously, but they might not be compatible in some cases, as you've mentioned.

To address your specific scenario:

  • Contrib as an Extra: It's possible to have the contrib package as an "extra" package alongside the base package. However, this typically involves manually managing which modules are enabled or disabled, and it might require recompilation of the OpenCV library, which can be complex.

  • Virtual Environments: A cleaner approach to managing dependencies is to use virtual environments. Create separate virtual environments for each of your projects or dependencies, each with its specific OpenCV package (base or contrib). This way, you can avoid conflicts between different projects that have different OpenCV requirements.

Here's a simplified example of how you can create a virtual environment and install specific OpenCV packages:

# Create a virtual environment for your first project
python -m venv project1-venv
source project1-venv/bin/activate

# Install the base OpenCV package
pip install opencv-python

# Do your work in this environment

# When done, deactivate the environment
deactivate

# Create a virtual environment for your second project
python -m venv project2-venv
source project2-venv/bin/activate

# Install the contrib OpenCV package
pip install opencv-contrib-python

# Do your work in this environment

# When done, deactivate the environment
deactivate

This approach isolates dependencies for each project, preventing conflicts between the base and contrib OpenCV packages.

@daveisfera
Copy link

I don't believe I explained the issue correctly, but how can you handle when one dependency needs opencv-python and another needs opencv-contrib-python? That means they're in the same project and only a single venv can be used, so there's no way to separate them. If there's a way to handle that, then I'll definitely use it, but from my current understanding, it appears that changing contrib to be an extra is the only solution.

@Mattral
Copy link

Mattral commented Oct 2, 2023

How about we use containerization tools like Docker to isolate dependencies in separate containers. we can create two separate containers, each with its own OpenCV package, and run the respective dependency within its container. I think this approach allows us to keep the dependencies separate while still working within the same project.

@daveisfera
Copy link

Sorry, when I say "project", I mean a single application, so it can't be separated. Basically, we are already using containers to run our application but we already have a dependency that uses opencv-python and we want to upgrade to a newer version of another package that wants to add opencv-contrib-python so they would both be in the same container.

@Mattral
Copy link

Mattral commented Oct 2, 2023

I see...... I understand the problem.
Renaming during installing (like headless ceses) may not work either.
I guess it is beyond my capability.( assuming that we cannot custom make the package)
However.....
As a last resort, you can try a more hacky approach where you create a virtual environment inside your container, install one of the OpenCV packages, and then create an alias so that the second dependency thinks it's using the required OpenCV package. Here's a simplified example:

//Create a virtual environment and install opencv-python or opencv-contrib-python
RUN python -m venv /venv
RUN /venv/bin/pip install opencv-contrib-python  # Or opencv-python

//Create an alias so that the second dependency thinks it's using opencv-python
RUN echo "alias python='/venv/bin/python'" >> ~/.bashrc

This approach can be quite hacky and may not work perfectly in all cases, but I guess it can sometimes help in resolving conflicts.

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

3 participants