Book Image

Computer Vision Projects with OpenCV and Python 3

By : Matthew Rever
Book Image

Computer Vision Projects with OpenCV and Python 3

By: Matthew Rever

Overview of this book

Python is the ideal programming language for rapidly prototyping and developing production-grade codes for image processing and Computer Vision with its robust syntax and wealth of powerful libraries. This book will help you design and develop production-grade Computer Vision projects tackling real-world problems. With the help of this book, you will learn how to set up Anaconda and Python for the major OSes with cutting-edge third-party libraries for Computer Vision. You'll learn state-of-the-art techniques for classifying images, finding and identifying human postures, and detecting faces within videos. You will use powerful machine learning tools such as OpenCV, Dlib, and TensorFlow to build exciting projects such as classifying handwritten digits, detecting facial features,and much more. The book also covers some advanced projects, such as reading text from license plates from real-world images using Google’s Tesseract software, and tracking human body poses using DeeperCut within TensorFlow. By the end of this book, you will have the expertise required to build your own Computer Vision projects using Python and its associated libraries.
Table of Contents (9 chapters)

Plate utility functions

Let's jump to our code in Jupyter Notebook, in order to understand plate utility functions. We will first embed the imports with our utilities.

We will be importing the following libraries:

  • OpenCV (version 3.4)
  • NumPy
  • Pickle, which lets us save Python data and case functions

Import the libraries as follows:

import cv2
import numpy as np
import pickle
def gray_thresh_img(input_image):
h, w, _ = input_image.shape
grayimg = cv2.cvtColor(input_image, cv2.COLOR_BGR2HSV)[:,:,2]

kernel = cv2.getStructuringElement(cv2.MORPH_RECT, (3, 3))

tophat = cv2.morphologyEx(grayimg, cv2.MORPH_TOPHAT, kernel)
blackhat = cv2.morphologyEx(grayimg, cv2.MORPH_BLACKHAT, kernel)
graytop = cv2.add(grayimg, tophat)
contrastgray = cv2.subtract(graytop, blackhat)
blurred = cv2.GaussianBlur(contrastgray, (5,5), 0)
thesholded = cv2.adaptiveThreshold...