-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
70 lines (53 loc) · 2.2 KB
/
main.py
File metadata and controls
70 lines (53 loc) · 2.2 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
60
61
62
63
64
65
66
67
68
69
70
import os
import cv2 as cv
import matplotlib.pyplot as plt
import numpy as np
import glob
np.set_printoptions(suppress=True, formatter={'float_kind':'{:0.5f}'.format})
# My library
import calibration as cal
import camera_pose as cam
import plane_sweeping as pl
# Get current working directory and locate images
curr_work_dir = os.getcwd()
img_path = curr_work_dir + "/images/"
chessboard_path = img_path + "chessboard/"
scene_path = img_path + "scene/"
#-----------------------------------------------------------------#
# Part 1
#-----------------------------------------------------------------#
# Chessboard pattern images
chessboard_imgs = glob.glob(chessboard_path +'*.jpg')
# Intrinsic matrix, K
ret, K, dist, rvecs, tvecs, mse = cal.camera_calibration()
print("K:\n", K)
# Radial distortion coefficients
print("\nRadial distortion coefficients:\n", dist)
# Reprojection mean square error
print("\nMean square error: ", "{:.5f}".format(mse))
#-----------------------------------------------------------------#
# Part 2
#-----------------------------------------------------------------#
# Images of similar scene and w/ objects at different distances
scene_imgs = glob.glob(scene_path +'*.jpg')
#-----------------------------------------------------------------#
# Part 3
#-----------------------------------------------------------------#
#relative_camera_pose()
img1 = scene_path + "left.jpg"
img2 = scene_path + "right.jpg"
test= cv.imread(img1)
print("*********test", test.shape)
R1, R2, t = cam.relative_camera_pose(img1, img2, K, dist)
# Epipolar lines on the images
# Matrix R_R_L and r_R
#print("\nRotation matrix left to right:\n", R1)
#print("\nTranslation vector from right reference frame:\n", t)
# Re-projected feature points on the first image
#-----------------------------------------------------------------#
# Part 4
#-----------------------------------------------------------------#
# https://opencv-python-tutroals.readthedocs.io/en/latest/py_tutorials/py_calib3d/py_depthmap/py_depthmap.html#py-depthmap
# d_min and d_max
# N=20 warped second images
# Resulting depth image, in grayscale