+

Configure Opencv in an anaconda environment

Requirements for OpenCV and Anaconda
— 32- or 64-bit computer. 
— for Miniconda — 400 MB of disk space. 
— For Anaconda — at least 3 GB of disk space for download and installation. 
— Windows, MacOS or Linux. 
— Python 2.7, 3.4, 3.5 or 3.6.

ANACONDA

Anaconda — it is open source software containing jupiter, spies, etc., which are used for big data processing, data analysis, heavy scientific computing. Anaconda works in the R and Python programming languages. Spyder (Anaconda sub-application) is used for Python. OpenCV for Python will work in Skyder. Package versions are controlled by the conda package management system. 

Installing Anaconda: Go to Continumum.io/downloads/ and install the latest version of Anaconda. Be sure to install "Python 3.6 Version" for the appropriate architecture. Install it with the default settings.

OpenCV

OpenCV (Open Source Computer Vision) — is a computer vision library that contains various functions for performing operations on images or videos. It was originally developed by Intel, but was later backed by Willow Garage and is now backed by Itseez. This library is cross-platform, meaning it is available in several programming languages ​​such as Python, C ++, etc.

Steps to import OpenCV to Anaconda on Windows & # 39;

  1. Create Anaconda environment:
    Step 1: — Search for Anaconda in the taskbar and select ANACONDA NAVIGATOR. 

    Step 2 : — Now you will see a menu with different options like Jupiter notepad, Spyder, etc. This is Anaconda Environment. 
    Step 3: — Select Spyder as it is an Anaconda IDE for Python and the OpenCV library will only run in it.

  2. Install OpenCV
    Step 1: — After installing anaconda, open Anaconda`s hint.


    Step 2: — Enter this command, hit enter and let it download the entire package. 
    command

     conda install -c menpo opencv 

    Step 3: — Now just import opencv into your python program, in which you want to use the image processing functions.

Examples: some basic functions of the opencv library (these functions are performed for the Windows version of Anaconda, but it also works for linux version)

  • Reading an image
     img = cv2.imread (`LOCATION OF THE IMAGE`)  

    The above imread function saves the image at a given location in the img variable.

  • Convert the image to grayscale
     img = cv2.imread (`watch .jpg`, cv2.IMREAD_GRAYSCALE) 

    The above function converts the image to grayscale and then stores it in the img variable.

  • Display the saved image
     cv2.imshow (`image`, img) 

    The above function shows the image stored in the img variable.

  • Save image to file
     imwrite (filename, img) 

    The above function saves the image to file. The image is stored in a Mat variable in the form of a matrix.

  • Reading video directly from the webcam
     cap = cv2.VideoCapture (0) 

    Stores live video from your webcam in a variable cap.

  • Read video from local storage
     cap = cv2.VideoCapture (`LOCATION OF THE VIDEO`) 

    Saves the video at the given location to a variable.

  • To check if the video was saved successfully to a variable
     cap.isOpened () 

    cap — it is a variable that contains the video. The above function returns true if the video was opened successfully, otherwise it returns false.

  • Release the saved video after processing is complete
     cap.release () 

    The above function frees up the video stored in the header.

Get Solution for free from DataCamp guru