How to Install OpenCV_Contrib Module in Anaconda?

Get Opencv Contrib Module In Anaconda

While the OpenCV package offers a variety of features, the contrib modules provide useful extras for specialized tasks. The process of installing these modules means handling dependencies and pointing installers to non-standard module locations hosted online.

Thankfully, with a bit of direction, adding OpenCV contrib modules on Anaconda is straightforward enough for intermediate Python developers. We will walk through the steps while explaining the rationale behind key decisions.

If you haven’t installed Anaconda yet, install it first.

Also refer: Step-by-Step Guide to Installing Python Using Conda

Step-by-Step Installation of OpenCV Contrib in Anaconda

To get the opencv-contrib module in Anaconda, follow these steps:

  • The first step is activating a conda environment where we will install the ‘opencv-contrib‘ module. Open the anaconda prompt and activate the conda environment using the following command:
conda activate conda_env

This command will activate the conda environment that is the ‘conda-env‘ environment. You can replace the environment name ‘conda-env‘ with the environment name where you want to install the ‘opencv-contrib‘ module.

Opencv Activate1

We activated our ‘conda-env‘ environment.

  • First, check the Python version of your conda environment. It supports Python 3.6.x. You can create a new environment with Python 3.6 version or you can update the Python version of your activated conda environment.

To create a new environment with Python 3.6 version use the following command:

conda create -n my_env python=3.6

To update the Python version of your current activated conda environment use the following command:

conda install python=3.6

Also read: How to change the Python version of the conda virtual environment?

  • To install the ‘opencv-contrib‘ module, we have to first install ‘opencv‘ in our Anaconda environment. We will install the ‘opencv‘ using the following command:
conda install -c conda-forge opencv

Here we are installing the ‘opencv‘ package from the ‘conda-forge‘ channel, a community-driven collection of conda packages.

Enter y to proceed.

We installed an ‘opencv‘ package.

  • After installing ‘opencv‘, we will install ‘opencv-contrib‘. Use the following command to install ‘opencv-contrib‘:
conda install -c michael_wild opencv-contrib

Here we are installing an ‘opencv-contrib‘ package from the ‘michael_wild‘ channel.

Enter y to proceed.

Opencv Contrib

Now you successfully get the ‘opencv-contrib‘ module in your Anaconda Python environment.

Once installed, you can import the cv2 module in your Python script to access the ‘opencv‘ functionalities.

Why Using OpenCV Contrib with Anaconda is Helpful

  • OpenCV and Python are both easy for beginners and experts to use for computer vision. Anaconda makes installing OpenCV even simpler.
  • Anaconda handles dependencies and compatibility so OpenCV is installed smoothly with one command.
  • Anaconda lets you create separate environments for different projects and Python versions without messing up other environments.
  • This reduces chances of stuff not working well together.
  • The ‘michael_wild’ Anaconda channel has the OpenCV contrib package to add extra stuff.
  • It’s easy to switch between Anaconda environments that have different OpenCV contrib versions.
  • You can make virtual environments in Anaconda to manager OpenCV contrib versions for different projects.

Summary

The OpenCV contrib modules provide extra capabilities for specialized computer vision tasks. However, installing them involves managing tricky dependencies and directing installers to non-standard online locations. Anaconda simplifies matters through automated dependency and environment handling, reducing compatibility issues.

Creating separate Anaconda environments for different projects and Python versions prevents conflicts without disrupting other setups. Switching between environments running different OpenCV contrib versions remains straightforward. Virtual Anaconda environments can also isolate OpenCV contrib variants on a per-project basis.

In essence, having a preconfigured OpenCV contrib package in Anaconda saves the trouble of manual installation and dependency wrangling. Connecting modules to the Anaconda ecosystem empowers developers to construct more potent computer vision solutions. They can tap the strengths of both platforms to build deep-learning object detectors, advanced image processors and other intricate applications with greater efficiency.

Reference

https://stackoverflow.com/questions/42886286/how-to-get-opencv-contrib-module-in-anaconda