def project(self, X, check_bounds=False, check_depth=False, return_depth=False, min_depth=0.1):
"""
Project [Nx3] points onto 2-D image plane [Nx2]
"""
R, t = self.to_Rt()
rvec,_ = cv2.Rodrigues(R)
proj,_ = cv2.projectPoints(X, rvec, t, self.K, self.D)
x = proj.reshape(-1,2)
if check_depth:
# Only return positive depths
depths = self.depth_from_projection(X)
valid = depths >= min_depth
else:
valid = np.ones(len(x), dtype=np.bool)
if check_bounds:
if self.shape is None:
raise ValueError('check_bounds cannot proceed. Camera.shape is not set')
# Only return points within-image bounds
valid = np.bitwise_and(
valid, np.bitwise_and(
np.bitwise_and(x[:,0] >= 0, x[:,0] < self.shape[1]), \
np.bitwise_and(x[:,1] >= 0, x[:,1] < self.shape[0]))
)
if return_depth:
return x[valid], depths[valid]
return x[valid]
评论列表
文章目录