The Setup

Introduction to OpenCV

What is Computer Vision?

If you were to present an image of a tree to a computer, a computer would have no way of recognizing that the object in question is indeed a tree. To take things a step further, the computer would not be able to even understand what the definition of an object is. So what data can be extracted from an image that a computer can understand? Luckily a computer can understand the pixels that make up the image and their associated RGB values. This is what makes much of the foundation for computer vision: Using the pixel values of an image to allow computers to make informed decisions. Understanding this, we can write programs and make definitions to make it so a computer can recognize different objects such as trees by utilizing and manipulating the pixel values.

What is OpenCV?

When it comes to computer vision, OpenCV is an open-source library that is widely used and sponsored by the likes of Microsoft and Google. It contains a myriad of functions that can assist you in creating programs that are designed to handle tasks related to computer vision.

How do I get started?

  • First, open your Visual Studio Code program and open a new program and go down to the terminal window.

  • Then you will want to enter the following command into the terminal window: pip install opencv-python


  • This will go ahead and install the OpenCV library into your Visual Studio Code, and from there, you can import the library in any program you desire.


  • When you import the library it will be called cv2, so you will type in "import cv2" at the top of your program when you need to do so.

Pre-Assignment

  • Make a folder in your directory called "Photos"

  • You can do this by clicking the new folder icon at the top of the directory.

  • Then, download the picture in the pre-assignment folder, and move it to your photos directory.

  • Make sure the image is in .jpg format

  • Copy name of the image (not the .jpg part just the name). You will need this for the next module.

NOTE: For the following modules the code builds on the previous module's work, so please keep all of the code in one file.