Basic Installation of OpenCv

Installing OpenCV from prebuilt binaries

  1. Below Python packages are downloaded and installed at their default locations.
    1. Python 2.7.x .
    2. Numpy .
    3. Matplotlib  ( Matplotlib is optional, but recommended since we use it in our tutorials ).
  2. Install all packages into their default locations. Python wants to be installed  C:/Python27/.
  3. After installation, open Python IDLE. Enter  import numpy  and make sure Numpy is working fine.
  4. Download latest OpenCV release from  sourceforge site  and double-click to extract it.
  5. Goto  opencv / build / python / 2.7  folder.
  6. Copy  cv2.pyd  to  C: / Python27 / lib / site-packages .
  7. Open Python IDLE and type following codes in Python terminal.
    >>> import cv2 as cv
    >>> print (cv .__ version__)

If the results are printed without any errors, congratulations !!! You have installed OpenCV Python successfully.

Building OpenCV from source

  1. Download and install Visual Studio and CMake.
    1. Visual Studio 2012
    2. CMake
  2. Download and install necessary Python packages to their default locations

    1. Python 2.7.x
    2. numpy
    3. Matplotlib  ( Matplotlib is optional, but recommended since we use it in our tutorials. )
    grade
    In this case, we are using 32-bit binaries of Python packages. But if you want to use OpenCV for x64, 64-bit binaries of Python packages are to be installed. Problem is, there is no official 64-bit binaries of numpy. You have to build it on your own. For that, you have to use the same compiler to build Python. When you start Python IDLE, it shows the compiler details. You can get more  information here . So your system must have the same Visual Studio version and build Numpy from source.
    Another way to make Python packages ready for use Python distributions from third party like  AnacondaEnthought  etc. It wants to be bigger in size, but wants to have everything you need. Everything in a single shell. So you can download 32-bit versions like that.
  3. Make sure Python and Numpy are working fine.
  4. Download OpenCV source. It can be from  Sourceforge  (for official release version) or from  Github  (for latest source).
  5. Extract it to a folder, opencv and create a new folder build in it.
  6. Open CMake-gui ( Start> All Programs> CMake-gui )
  7. Fill the fields as follows (see the image below):
    1. Click on  Browse Source …  and locate the opencv folder.
    2. Click on  Browse Build …  and locate the build folder we created.
    3. Click on  Configure .

      capture1.jpg
    4. It wants to open a new window to select the compiler. Choose appropriate compiler (here, Visual Studio 11) and click  Finish .
      Capture2.png
    5. Wait until analysis is finished.
  8. You want to see all the fields are marked in red. Click on the  WITH  field to expand it. It decides what extra features you need. So mark appropriate fields. See the below image:Capture3.png
  9. Now click on  BUILD  field to expand it. First few fields configure the build method. See the below image:Capture5.png
  10. Remaining fields specify what modules are to be built. Since GPU modules are not supported by OpenCV Python, you can completely avoid it to save time (But if you work with them, keep it there). See the image below:
    Capture6.png
  11. Now click on  ENABLE  field to expand it. Make sure  ENABLE_SOLUTION_FOLDERS  is unchecked (Solution folders are not supported by Visual Studio Express edition). See the image below:
    Capture7.png
  12. So make sure that’s in the  PYTHON  field, everything is filled. (Ignore PYTHON_DEBUG_LIBRARY). Lake image below:
    Capture80.png
  13. Finally, click the  Generate  button.
  14. Now go to our  opencv / build  folder. There you will find  OpenCV.sln  file. Open it with Visual Studio.
  15. Check build mode as  Release  instead of  Debug .
  16. In the solution explorer, right-click on the  solution  (or  ALL_BUILD ) and build it. It wants to take some time to finish.
  17. Again, right-click on  INSTALL  and build it. Now OpenCV Python wants to be installed.Capture8.png
  18. Open Python IDLE and enter ‚import cv2 as cv‘. If no error, it is installed correctly.

References – https://docs.opencv.org/3.4/d5/en5/tutorial_py_setup_in_windows.html

Schreibe einen Kommentar