-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcorner.py
38 lines (34 loc) · 1.64 KB
/
corner.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
################ FIND CHESSBOARD CORNERS - OBJECT POINTS AND IMAGE POINTS #############################
chessboardSize = (6, 6)
frameSize = (1920, 1080) # frame size oder resolution
# # Define the algorithm termination criteria
criteria = (cv.TERM_CRITERIA_EPS + cv.TERM_CRITERIA_MAX_ITER,
30, # Max number of iteration
0.001 # Epsilon)
objp = np.zeros((chessboardSize[0] * chessboardSize[1], 3), np.float32)
# prepare object points, like (0,0,0), (1,0,0), (2,0,0) ....,(6,5,0)
objp[:, :2] = np.mgrid[0:chessboardSize[0], 0:chessboardSize[1]].T.reshape(-1, 2)
# zeroes with coordinate value like 0,0,0 1,0,0 2,0,0 ...0,1,0 ... 5,5,0
size_of_chessboard_squares_mm = 20
objp = objp * size_of_chessboard_squares_mm # array of 6*6
# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.
path = r"C:\Users\Akshay\Downloads\data\*.png"
images = glob.glob(path)
for image in images:
img = cv.imread(image) # read the image
gray = cv.cvtColor(img, cv.COLOR_BGR2GRAY) # covert to gray scale
# Find the chess board corners
ret, corners = cv.findChessboardCorners(gray, chessboardSize, None)
if ret == True:
print("chessboard found")
objpoints.append(objp)
corners2 = cv.cornerSubPix(gray, corners, (11, 11), (-1, -1), criteria)
imgpoints.append(corners2)
# Draw and display the corners
cv.drawChessboardCorners(img, chessboardSize, corners2,ret)
cv.imshow('img', img)
cv.imwrite('res.png', img)
cv.waitKey(1000)
cv.destroyAllWindows()