Permalink
Switch branches/tags
Nothing to show
Find file Copy path
83df512 Mar 1, 2017
1 contributor

Users who have contributed to this file

25 lines (21 sloc) 865 Bytes
import numpy as np
import cv2
def flatten_perspective(image):
"""
Warps the image from the vehicle front-facing camera mapping hte road to a bird view perspective.
Parameters
----------
image : Image from the vehicle front-facing camera.
Returns
-------
Warped image.
"""
# Get image dimensions
(h, w) = (image.shape[0], image.shape[1])
# Define source points
source = np.float32([[w // 2 - 76, h * .625], [w // 2 + 76, h * .625], [-100, h], [w + 100, h]])
# Define corresponding destination points
destination = np.float32([[100, 0], [w - 100, 0], [100, h], [w - 100, h]])
transform_matrix = cv2.getPerspectiveTransform(source, destination)
unwarp_matrix = cv2.getPerspectiveTransform(destination, source)
return (cv2.warpPerspective(image, transform_matrix, (w, h)), unwarp_matrix)