-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathperspective.py
More file actions
25 lines (21 loc) · 865 Bytes
/
Copy pathperspective.py
File metadata and controls
25 lines (21 loc) · 865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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)