Book Image

The Computer Vision Workshop

By : Hafsa Asad, Vishwesh Ravi Shrimali, Nikhil Singh
Book Image

The Computer Vision Workshop

By: Hafsa Asad, Vishwesh Ravi Shrimali, Nikhil Singh

Overview of this book

Computer Vision (CV) has become an important aspect of AI technology. From driverless cars to medical diagnostics and monitoring the health of crops to fraud detection in banking, computer vision is used across all domains to automate tasks. The Computer Vision Workshop will help you understand how computers master the art of processing digital images and videos to mimic human activities. Starting with an introduction to the OpenCV library, you'll learn how to write your first script using basic image processing operations. You'll then get to grips with essential image and video processing techniques such as histograms, contours, and face processing. As you progress, you'll become familiar with advanced computer vision and deep learning concepts, such as object detection, tracking, and recognition, and finally shift your focus from 2D to 3D visualization. This CV course will enable you to experiment with camera calibration and explore both passive and active canonical 3D reconstruction methods. By the end of this book, you'll have developed the practical skills necessary for building powerful applications to solve computer vision problems.
Table of Contents (10 chapters)

1. Basics of Image Processing

Activity 1.01: Mirror Effect with a Twist

Solution:

  1. Let's start by importing the necessary libraries:
    # Load modules
    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
  2. Next, let's specify the magic command for displaying images in a notebook:
    %matplotlib inline
  3. Now, we can load the image and display it using Matplotlib.

    Note

    Before proceeding, ensure that you can change the path to the images (highlighted) based on where the image is saved in your system.

    The code is as follows:

    # Load image
    img = cv2.imread("../data/lion.jpg")
    plt.imshow(img[:,:,::-1])
    plt.show()

    The output is as follows:

    Figure 1.42: Image that we are going to use in this activity

  4. Next, let's display the image's shape:
    # Get image shape
    img.shape

    The output is (407, 640, 3).

  5. Convert the image into HSV:
    # Convert image to HSV
    imgHSV = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    plt.imshow(imgHSV[:,:,::-1])
    plt.show()

    The output is as follows...