OpenCV

From Alliance Doc
Jump to navigation Jump to search
This site replaces the former Compute Canada documentation site, and is now being managed by the Digital Research Alliance of Canada.

Ce site remplace l'ancien site de documentation de Calcul Canada et est maintenant géré par l'Alliance de recherche numérique du Canada.

Other languages:

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.

Question.png
[name@server ~]$ 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 discover which are the compatible Python versions, run

Question.png
[name@server ~]$ module spider opencv/X.Y.Z

Or search directly opencv_python, by running

Question.png
[name@server ~]$ module spider opencv_python/X.Y.Z

where X.Y.Z represent the desired version.

Usage

1. Load the required modules.

Question.png
[name@server ~]$ module load gcc opencv/X.Y.Z python scipy-stack

where X.Y.Z represent the desired version.

2. Import OpenCV.

Question.png
[name@server ~]$ 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
Question.png
[name@server ~]$ 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.

Question.png
[name@server ~]$ OPENCV_IO_ENABLE_OPENEXR=1 python <file>