-
Notifications
You must be signed in to change notification settings - Fork 4
/
fw_camcalib.py
43 lines (36 loc) · 1.1 KB
/
fw_camcalib.py
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
from cv2 import *
import numpy as np
# import cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import glob
folder = 'D:/Repos/CarND-Advanced-Lane-Lines/'
#img = mpimg.imread(folder + 'camera_cal/calibration2.jpg')
imgs = glob.glob(folder + 'camera_cal/calibration*.jpg' )
objp = np.zeros((9*6,3), np.float32)
objp[:,:2] = np.mgrid[0:9,0:6].T.reshape(-1,2)
objpoints = []
imgpoints = []
pattern = (9,6)
for fname in imgs:
fname = imgs[0]
img = cv2.imread(fname)
plt.imshow(img)
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
plt.imshow(gray)
ret, crnrs = cv2.findChessboardCorners(gray,pattern,None)
if ret == True:
imgpoints.append(crnrs)
objpoints.append(objp)
else:
raise Exception('unable to read calibration image')
img.shape
g = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
plt.imshow(g)
ret, crnrs = cv2.findChessboardCorners(g,(9,6),None)
if ret == True:
imgpoints.append(crnrs)
objpoints.append(objp)
img = cv2.drawChessboardCorners(img,(9,6),crnrs,ret)
img = img[...,::-1] #brg to rgn
plt.imshow(img)