Skip to main content

Install OpenCV on Windows

warning

The how-to instruction is only valid for Work.AI versions up to 10.3.2. In 10.3.2, Python 3.7 was deprecated.

To install OpenCV version 4.3.0-DEV or later for Windows 10.x, do as follows:

  1. Install Python 3.7.7 or the latest version.

    1. Download the Windows x86-64 executable installer from https://www.python.org/downloads.

    2. On the RPA server, install the package for all users to C:/Python37.

    3. Verify that Python 3.7.7 is installed successfully.

      C:\Windows\System32> python --version
    4. Launch Command Prompt as an Administrator and run the following command to update pip.

      C:\Windows\System32> python -m pip install --upgrade pip
  2. Install the latest Visual Studio C++ Build Tools.

    1. Download the executable installer from https://visualstudio.microsoft.com/visual-cpp-build-tools.
    2. Install the package with default options selected.
  3. Install the latest Git.

    1. Download the 64-bit Git for Windows Setup installer from https://git-scm.com/download/win.
    2. Install the package with the default text editor set as Sublime Text 3 and other default options selected.
  4. Install the latest CMake.

    1. Download the Windows win64-x64 installer from https://cmake.org/download.
    2. Install the package with selected default options.
  5. Install the latest Visual Studio Community.

    1. Download the executable installer from https://visualstudio.microsoft.com/downloads.

    2. Install the package with the Desktop Development with the selected C++ option. Optionally, change the grouping name on the second page from 2 to the Visual Studio version (15, 16, and so on).

    3. Launch Command Prompt as an Administrator and run the following command to install NumPy:

      C:\Windows\System32> pip install numpy
    4. Check if 4.3.0-DEV is available from https://pypi.org/project/opencv-python and https://pypi.org/project/opencv-contrib-python.

      • If they are available, launch Command Prompt as an Administrator and run the following two commands to install them:

        C:\Windows\System32> pip install opencv-python
        C:\Windows\System32> pip install opencv-contrib-python
      • If they are not available, continue to Step 7 to build OpenCV from source.

    5. Launch Command Prompt as an Administrator and run the following commands to download the source code from GitHub.

      C:\Windows\System32> mkdir C:\projects && cd C:\projects && mkdir build
      C:\Windows\System32> git clone https://github.com/opencv/opencv.git
      C:\Windows\System32> git clone https://github.com/opencv/opencv_contrib.git
    6. Begin installing OpenCV from source. Before you begin, refer to this guide.

    7. Set source to C:/projects/opencv.

    8. Set build to C:/projects/build.

    9. Select Grouped and Advanced.

    10. Hit Configure.

    11. Select Visual Studio 16 2019 as the generator.

    12. Select x64 as the platform.

    13. Select Use native default compilers.

    14. Hit Finish.

    15. Set BUILD "BUILD_PERF_TESTS=OFF".

    16. Set BUILD "BUILD_TESTS=OFF".

    17. Set ENABLE "ENABLE_SOLUTION_FOLDERS=OFF".

    18. Set OPENCV "OPENCV_ENABLE_NONFREE=ON".

    19. Set OPENCV "OPENCV_EXTRA_MODULES_PATH=C:/projects/opencv_contrib/modules".

    20. Set OPENCV "OPENCV_PYTHON3_VERSION=ON".

    21. Confirm PYTHON3 "PYTHON3_NUMPY_INCLUDE_DIRS=C:/Python37/lib/site-packages/numpy/core/include".

    22. Hit Generate.

    23. Open C:\projects\build\ALL_BUILD.vcxproj in Visual Studio Community.

    24. Change mode from Debug to Release.

    25. Select Build for ALL_BUILD (takes up to 30 minutes).

    26. Select Build for INSTALL.

  6. Install PIP to set up and manage Python modules:

    1. Launch Command Prompt as an Administrator and run the following command to install Wheel:

      C:\Windows\System32> pip install wheel
    2. Launch Command Prompt as an Administrator and run the specified command from https://pytorch.org/get-started/locally (Stable/Windows/Pip/Python/None) to install PyTorch:   

      C:\Windows\System32> pip install torch==1.5.0+cpu torchvision==0.6.0+cpu -f https://download.pytorch.org/whl/torch_stable.html
    3. Launch Command Prompt as an Administrator and run the following commands to install any additional Python modules:

      C:\Windows\System32> pip install lxml
      C:\Windows\System32> pip install requests
      C:\Windows\System32> pip install matplotlib
      C:\Windows\System32> pip install tqdm
      C:\Windows\System32> pip install boto3
      C:\Windows\System32> pip install pandas
  7. To check the OpenCV installation, verify that OpenCV 4.3.0-DEV is installed successfully.

    C:\Windows\System32> python
    >>> import cv2
    >>> print(cv2.__version__)
note

Python is not pre-installed on RPA servers.