Skip to content

OpenCV/en

OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real-time computer vision.

CUDA

OpenCV is also available with CUDA.

module load gcc cuda opencv/X.Y.Z

where X.Y.Z represent the desired version.

Extra modules

The module also contains the extra modules (contrib).

Python bindings

The module contains bindings for multiple Python versions. To know which are the compatible Python versions, run

module spider opencv/X.Y.Z

Or search directly opencv_python, by running

module spider opencv_python/X.Y.Z

where X.Y.Z represent the desired version.

Usage

  1. Load the required modules.

    module load gcc opencv/X.Y.Z python scipy-stack
    

    where X.Y.Z represent the desired version.

  2. Import OpenCV.

    python -c "import cv2"
    

    If the command displays nothing, the import was successful.

Available Python packages

Other Python packages depend on OpenCV bindings in order to be installed. OpenCV provides four different packages: * opencv_python * opencv_contrib_python * opencv_python_headless * opencv_contrib_python_headless

pip list | grep opencv
opencv-contrib-python              4.5.5
opencv-contrib-python-headless     4.5.5
opencv-python                      4.5.5
opencv-python-headless             4.5.5

With the opencv module loaded, your package dependency for one of the OpenCV named will be satisfied.

Use with OpenEXR

In order to read EXR files with OpenCV, the module must be activated through an environment variable.

OPENCV_IO_ENABLE_OPENEXR=1 python <file>

Troubleshooting

This is a normal error generated by this dummy wheel.

See This is a normal error generated by this dummy wheel.

ModuleNotFoundError: No module named 'cv2'

When importing cv2, one may get the following error:

python -c "import cv2"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ModuleNotFoundError: No module named 'cv2'

This usually means one of the two following cases: 1. A module for OpenCV was not loaded 2. A Python module was not loaded

Module OpenCV not loaded

Find a compatible OpenCV module and load it. See Python bindings

Python module not loaded

When omitting to load a Python module and activating a virtual environment, the Python bindings will not be available, hence resulting in cv2 not being seen.

To remedy:

  1. Deactivate any Python virtual environment.

    test $VIRTUAL_ENV && deactivate
    

    Note

    If you had a virtual environment activated, it is important to deactivate it first, then load the module, before reactivating your virtual environment.

  2. Load the module.

    module load opencv/x.y.z python/x.y.z
    
  3. Check that it is visible by pip

    pip list | grep opencv
    
    opencv_python            4.13.0
    

    and is accessible for your currently loaded Python module.

    python -c 'import cv2'
    

    If no errors are raised, then everything is OK!