def dvs_img(cloud, shape, K, D): cmb = pydvs.dvs_img(cloud, shape, K=K, D=D) cmb[:, :, 0] *= global_scale_pp cmb[:, :, 1] *= 255.0 / slice_width cmb[:, :, 2] *= global_scale_pn return cmb
def dvs_img(cloud, shape, K, D, slice_width, mode=0): cmb = pydvs.dvs_img(cloud, shape, K=K, D=D) ncnt = cmb[:, :, 0] time = cmb[:, :, 1] pcnt = cmb[:, :, 2] cnt = pcnt + ncnt # Scale up to be able to save as uint8 # For visualization only. May cause overflow if slice_width is large cmb[:, :, 0] *= 50 cmb[:, :, 1] *= 255.0 / slice_width cmb[:, :, 2] *= 50 if (mode == 1): cmb = np.dstack((time, pcnt, ncnt)) return cmb
def __init__(self, shape, cloud): random.seed() self.shape = shape self.width = 0 self.dgrad = np.zeros((self.shape[0], self.shape[1], 3)) if (cloud.shape[0] > 0): self.width = cloud[-1][0] - cloud[0][0] self.dvs_img = pydvs.dvs_img(cloud, self.shape, model=[0, 0, 0, 0], scale=1, K=None, D=None) #self.dvs_img[:,:,1] = cv2.medianBlur(self.dvs_img[:,:,1], 5) self.dvs_img[:, :, 1] = cv2.GaussianBlur(self.dvs_img[:, :, 1], (7, 7), 0) dgrad = np.zeros((self.dvs_img.shape[0], self.dvs_img.shape[1], 2), dtype=np.float32) self.x_err2, self.y_err2, self.yaw_err, self.z_err2, self.e_count, self.nz_avg = \ pydvs.dvs_flow_err(self.dvs_img, dgrad) dgrad = np.zeros((self.dvs_img.shape[0], self.dvs_img.shape[1], 2), dtype=np.float32) self.x_err, self.y_err, self.yaw_err, self.z_err, self.e_count, self.nz_avg = \ pydvs.dvs_err(self.dvs_img, dgrad) self.x_err *= 10 self.y_err *= 10 self.z_err /= 5 self.x_err2 /= 5 self.y_err2 /= 5 self.z_err2 /= 500 self.e_count /= 6250 self.e_count -= 1 self.nz_avg /= 4 self.nz_avg -= 1 self.p_count = np.sum(self.dvs_img[:, :, 0]) / 20000 self.n_count = np.sum(self.dvs_img[:, :, 2]) / 30000 self.g_count = self.p_count + self.n_count / 50000 self.p_count -= 1 self.n_count -= 1 self.g_count -= 1 #function image2vec #Important function! first one really related to HBV vectors dgrad[:, :, 0] = np.sqrt((dgrad[:, :, 0] * dgrad[:, :, 0]) + (dgrad[:, :, 1] * dgrad[:, :, 1])) * np.sign( dgrad[:, :, 0] * dgrad[:, :, 1]) dgrad[:, :, 1] = dgrad[:, :, 0] dgrad[dgrad > 1.8] = 1.8 self.dgrad[:, :, 0] = np.copy(dgrad[:, :, 0]) self.dgrad[:, :, 1] = np.copy(dgrad[:, :, 0]) self.dgrad[:, :, 2] = np.copy(dgrad[:, :, 0]) self.vec, self.feature_list, self.rescaled_feat = self.image2vec(dgrad) return #print (self.x_err, self.y_err, self.z_err, self.yaw_err, self.e_count, self.nz_avg) # Visualization c_img = self.dvs_img[:, :, 0] + self.dvs_img[:, :, 2] c_img = np.dstack((c_img, c_img, c_img)) * 0.5 / (self.nz_avg + 1e-3) self.dvs_img[:, :, 1] *= 1.0 / self.width t_img = np.dstack( (self.dvs_img[:, :, 1], self.dvs_img[:, :, 1], self.dvs_img[:, :, 1])) G_img = colorizeImage(dgrad[:, :, 0], dgrad[:, :, 1]) self.vis = np.hstack((t_img, G_img)) cv2.namedWindow('GUI', cv2.WINDOW_NORMAL) cv2.imshow('GUI', np.hstack((t_img, G_img))) cv2.waitKey(0)
def __init__(self, shape, cloud): random.seed() self.shape = shape self.width = 0 if (cloud.shape[0] > 0): self.width = cloud[-1][0] - cloud[0][0] # Compute images according to the model self.dvs_img = pydvs.dvs_img(cloud, self.shape, model=[0, 0, 0, 0], scale=1, K=None, D=None) #self.dvs_img[:,:,1] = cv2.medianBlur(self.dvs_img[:,:,1], 5) self.dvs_img[:,:,1] = cv2.GaussianBlur(self.dvs_img[:,:,1], (7,7), 0) #dvs_img = np.copy(dvs_img[:50,:50,:]) # Compute errors on the images dgrad = np.zeros((self.dvs_img.shape[0], self.dvs_img.shape[1], 2), dtype=np.float32) self.x_err2, self.y_err2, self.yaw_err, self.z_err2, self.e_count, self.nz_avg = \ pydvs.dvs_flow_err(self.dvs_img, dgrad) dgrad = np.zeros((self.dvs_img.shape[0], self.dvs_img.shape[1], 2), dtype=np.float32) self.x_err, self.y_err, self.yaw_err, self.z_err, self.e_count, self.nz_avg = \ pydvs.dvs_err(self.dvs_img, dgrad) self.x_err *= 10 self.y_err *= 10 self.z_err /= 5 self.x_err2 /= 5 self.y_err2 /= 5 self.z_err2 /= 500 self.e_count /= 6250 self.e_count -= 1 self.nz_avg /= 4 self.nz_avg -= 1 self.p_count = np.sum(self.dvs_img[:,:,0]) / 20000 self.n_count = np.sum(self.dvs_img[:,:,2]) / 30000 self.g_count = self.p_count + self.n_count / 50000 self.p_count -= 1 self.n_count -= 1 self.g_count -= 1 self.vec = self.image2vec(dgrad) return #print (self.x_err, self.y_err, self.z_err, self.yaw_err, self.e_count, self.nz_avg) # Visualization c_img = self.dvs_img[:,:,0] + self.dvs_img[:,:,2] c_img = np.dstack((c_img, c_img, c_img)) * 0.5 / (self.nz_avg + 1e-3) self.dvs_img[:,:,1] *= 1.0 / self.width t_img = np.dstack((self.dvs_img[:,:,1], self.dvs_img[:,:,1], self.dvs_img[:,:,1])) G_img = colorizeImage(dgrad[:,:,0], dgrad[:,:,1]) self.vis = np.hstack((t_img, G_img)) cv2.namedWindow('GUI', cv2.WINDOW_NORMAL) cv2.imshow('GUI', np.hstack((t_img, G_img))) cv2.waitKey(0)