Python, OpenCV, Open3D 를 이용하여 2장의 이미지로 3차원을 복원하는 예제를 통해 과정을 더 자세히 살펴보도록 하겠습니다.
(전체 코드는 글 하단에 있습니다.)
과정
1. Undistortion
2. Rectification
3. Disparity Map 얻기
4. Disparity map 을 Depth map 으로 바꾸기
5. Depth Map 을 이용한 Point Cloud reconstruction
예제 사진
Undistortion
카메라 왜곡을 먼저 펴주기 위해 Undistortion 을 수행합니다.
# Undistortion
imgL_undist = cv2.undistort(imgL, K, dist_coef, None, K)
imgR_undist = cv2.undistort(imgR, K, dist_coef, None, K)
# 검은 부분을 줄이기 위해 ROI 대로 이미지를 자르기
x, y, w, h = roi
imgL_undist = imgL_undist[y:y+h, x:x+w]
imgR_undist = imgR_undist[y:y+h, x:x+w]
for y in range(h):
for x in range(w):
z = depth[y, x]
if z > min_z and z < max_z:
x_ = (x - center_x) * z / focal_length
y_ = (y - center_y) * z / focal_length
xyz[y, x,:] = (int(x_), int(y_), int(z))
# Get RGB color
rgb[y, x] = imgL_ori_rgb[y, x]
이 과정을 통해 point cloud 를 획득할 수 있습니다.
+ Point cloud processing : 이후 속도 증가 및 PC 노이즈 제거를 위해 다음과 같은 후처리 과정을 진행했습니다.