forked from udacity/CarND-Advanced-Lane-Lines
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_persp.py
More file actions
59 lines (45 loc) · 1.38 KB
/
test_persp.py
File metadata and controls
59 lines (45 loc) · 1.38 KB
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb 12 20:44:33 2017
@author: roy
"""
from PIL import Image
import numpy as np
import pickle
import cv2
import matplotlib.pyplot as plt
from glob import glob
# read calibration data
with open('./cal_data.pk', 'rb') as fp:
data = pickle.load(fp)
camera_mt = data['cal']
dist_coeff = data['dist']
# read perspective matrix data
warp_data_file = './warp_data.pk'
with open(warp_data_file, 'rb') as fp:
data = pickle.load(fp)
persp_mt = data['mt']
persp_size = data['img_size']
img_msk = './test_images/straight_lines*.jpg'
img_files = glob(img_msk)
for img_file in img_files:
#read in image
image = np.asarray(Image.open(img_file).convert('L')).astype('float')
#undistort
undst_img = cv2.undistort(image,camera_mt, dist_coeff, None, camera_mt)
img_size=(image.shape[1]//2, image.shape[0])
#warp perspective
img_warped = cv2.warpPerspective(undst_img, persp_mt, img_size)
img_save = np.uint8(255*img_warped/np.max(img_warped))
#plt.figure(figsize=(12,9))
#plt.gray()
#plt.plot(img_save[300,:], 'ro')
#plt.show()
img_pil = Image.fromarray(img_save)
output_filename=img_file.replace('test_images', 'output_images')
img_pil.save(output_filename)
plt.figure(figsize=(12,9))
plt.gray()
plt.imshow(img_warped)
plt.title(img_file)