Skip to Content
OpenCV 3 Computer Vision with Python Cookbook
book

OpenCV 3 Computer Vision with Python Cookbook

by Aleksei Spizhevoi, Aleksandr Rybnikov
March 2018
Beginner to intermediate
306 pages
9h 54m
English
Packt Publishing
Content preview from OpenCV 3 Computer Vision with Python Cookbook

How to do it...

  1. Import the modules we need:
import cv2import numpy as np
  1. Implement a function which finds the intersection point of two lines:
def intersect(l1, l2):    delta = np.array([l1[1] - l1[0], l2[1] - l2[0]]).astype(np.float32)        delta = 1 / delta    delta[:, 0] *= -1        b = np.matmul(delta, np.array([l1[0], l2[0]]).transpose())    b = np.diagonal(b).astype(np.float32)            res = cv2.solve(delta, b)    return res[0], tuple(res[1].astype(np.int32).reshape((2)))
  1. Define a function which un-warps the perspective distortions by calculating the correspondence between four pairs of distorted and un-distorted points:
def rectify(image, corners, out_size):    rect = np.zeros((4, 2), dtype = "float32")    rect[0] = corners[0]    rect[1] = corners[1] rect[2] = corners[2] ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Learning OpenCV 3 Computer Vision with Python (Update)

Learning OpenCV 3 Computer Vision with Python (Update)

Joe Minichino, Joseph Howse
OpenCV 4 with Python Blueprints - Second Edition

OpenCV 4 with Python Blueprints - Second Edition

Dr. Menua Gevorgyan, Michael Beyeler (USD), Arsen Mamikonyan, Michael Beyeler

Publisher Resources

ISBN: 9781788474443Supplemental Content