Understanding Computer Vision :Part 2

  1. Obtaining the ‘Height’, ‘Width’ and ‘Depth’ of Image
  2. Finding R,G,B components of the Image
  3. Drawing using OpenCV

Loading an Image from Disk:

Before we perform any operations or manipulations of an image, it is important for us to load an image of our choice to the disk. We will perform this activity using OpenCV. There are two ways we can perform this loading operations. One way is to load the image by simply passing the image path and image file to the OpenCV’s “imread” function. The other way is to pass the image through a command line argument using python module argparse.

Fig 2.1 Loading an Image from Disk by hard coding the image path and name in code
Fig 2.2 Loading an Image using Argparse module
Fig 2.3 Loading Image fro different folder location using Argparse

Obtaining the ‘Height’, ‘Width’ and ‘Depth’ of Image

Since images are represented as NumPy arrays, we can simply use the .shape attribute to examine the width, height, and the number of channels

Fig 2.4 Prints the Height,Width and Depth of Image

Finding R,G,B components of the Image

Fig 2.5 BGR value printed after taking the pixel co-ordinate position (y,x)

Drawing using OpenCV

Lets learn how to draw different shapes like rectangle, square and circle using OpenCV by drawing circles to mask my eyes , rectangle to mask my lips and rectangle to mask the mantra-ray fish next to me.

Fig 2.6 Masked Photo of me with the mantra-ray fish.
Fig 2.7 MSPaint to find the co-ordinates of the masking region
Fig 2.8 (x.y) Co-ordinates of masking regions
Fig 2.9 Desired Output



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store


Bay of Tech : ”Affordable technology solutions to everyone” |BoT provides solutions in Industry 4.0 | This space is the perspective page of BoT