Installation OpenCV on Windows using Anaconda

10 minutes
6 months, 2 weeks ago
<h2><b>Overview</b></h2><p>1. Anaconda installation</p><p>2. OpenCV installation</p><h2><b>Introduction</b></h2><p><b>What is OpenCV?</b></p><p>OpenCV is an open-source C++ library i.e. it is free to use, the code for the whole package is available online [https://github.com/opencv] and all algorithms and scripts are implemented in C++.</p><p><b>What do you do with OpenCV?</b></p><p>CV in OpenCV stands for Computer Vision. In the most simplest sense, it deals with enabling computers to process whatever they see, like humans, and extract meaning out of it.</p><p>These are the following places where you have used image processing</p><p>1. When Facebook automatic tag suggestions feature.</p><p>2. Google image search</p><p>3. Instagram filters.</p><p>4. Your camera app in your face detection.</p><h2><b>Installation</b></h2><h3><b>1. Download Anaconda</b></h3><p>https://www.anaconda.com/download/#windows</p><p>and install it. All default settings.</p><p>For this tutorial we are using Python2.7.</p><p>Downloading VSCode is optional and hence your choice.</p><p><b>What is Anaconda?</b></p><p>Anaconda is basically a collection of all the basic open-source python packages so that there are no dependency errors in projects.</p><p>Earlier [like, 2 years ago] these packages were installed on windows through this: https://www.lfd.uci.edu/~gohlke/pythonlibs/</p><p>Anaconda made your work easy.</p><h3><b>2. Create a Virtual Environment</b></h3><p><b>What is a virtual environment?</b></p><p>Think of a virtual environment as an independent separate section of your windows. This is useful as whatever you download here is only limited to this environment and can't be accessed outside this section. So, if anything goes wrong, the effect would be contained and won't be reflected on your whole system.</p><p>a. When done, open the Anaconda Command Prompt from your start menu.</p><p>b. To create a virtual environment</p><pre>conda create --name &lt;your_environment_name&gt;</pre><p><b>What is conda?</b></p><p>Conda is a command line utility for Anaconda i.e. conda helps you interact with Anaconda using a command line.</p><p>If everything went right, you have created your environment</p><p>c. Activate your environment</p><pre>conda activate &lt;your_environment_name&gt;</pre><p>If you see &lt;your_environment_name&gt; as the first word on your command line, you have activated your environment.</p><h3><b>Virtual environment deactivation and deletion</b></h3><p>If after you're done with the OpenCV installation and you wish to deactivate/delete your environments;</p><p>a. deactivating an environment</p><pre>conda deactivate &lt;your_environment_name&gt;</pre><p>You deactivate your environment when you wish to work on some other environment or some other project where the packages installed in this environment aren't needed.</p><p>b. deleting an environment</p><pre>conda remove --name &lt;your_environment_name&gt; --all</pre><p>You delete your environment when you don't need it. As simple as that.</p><h3><b>3. Installing OpenCV</b></h3><p>We'll be installing the latest version of OpenCV, OpenCV 3.4</p><pre>$ conda install -c conda-forge opencv</pre><pre>$ conda install -c conda-forge/label/broken opencv</pre><h3><b>4. Check your installation</b></h3><p>When one installing OpenCV, you can check your installation by typing</p><pre>$ python</pre><p>You'll be treated with a python interpreter [remember this name] (google as to why it's called an interpreter and not a compiler)</p><p>If you'd installed with Python2.7, you'll see something like this:</p><pre>Python 2.7.12 (default, Dec 4 2017, 14:50:18)<br>[GCC 5.4.0 20160609] on linux2<br>Type "help", "copyright", "credits" or "license" for more information.<br>&gt;&gt;&gt;</pre><p>To check if you've installed OpenCV<br></p><pre>&gt;&gt;&gt;import cv2</pre><p>If nothing happens, congratulations!!! You have installed OpenCV on windows.</p><p>To check your OpenCV version type</p><pre>&gt;&gt;&gt;&gt;cv2.__version__</pre><h3><b>A basic code snippet using OpenCV</b></h3><p>Now that you've installed OpenCV, you might want to show others what you installed.</p><p>Below is a simple python script that lets you open your webcam using OpenCV.</p><pre>import cv2 #importing opencv <br>import numpy as np #importing numpy<br># main function<br># feed is whatever is captured by the camera<br>feed = cv2.VideoCapture(0)<br># while the feed is opened,<br>while(feed.isOpened()):<br> # we read each frame<br> ret, img = feed.read()<br> # and show those frames<br> cv2.imshow('Camera 0:', img)<br> # it waits for the esc key to be pressed so as to exit<br> if cv2.waitKey(10) == 27:<br> break</pre><p>Voila!! Your Webcam should open by now. If not, debug your errors.</p><h2><b>Conclusion</b></h2><p>That's all folks. This is how you install OpenCV on Windows. The easy way.</p><p>In the next tutorial, we'll apply OpenCV to detect a face in a camera feed. Till then, good luck!</p>

Comments

You must login to comment


when the face detection tutorial will be uploaded

via abantika | 5 months ago | Reply | Thread

You must login to comment