def load_mvs(self, num_segments, is_train): """ :param num_segments: :param is_train: :return: (counts, width//4, height//4, channels=2) 0,255 """ # mv_ref_arr=(H/4,W/4,frames*6) # mv_ref_arr is a array with 3 dimensions. The first dimension denotes Height of a frame. The second dimension denotes Width of a frame. # For every frame, it contains mv_0_x, mv_0_y, ref_0, mv_1_x, mv_1_y, ref_1. So, the third dimension denote frames*6. os.chdir(self.data_root) mv_origin = coviexinfo.extract(self.video_name, 'get_mv', self.num_frames, self.num_I, 0) if len(mv_origin) == 0: mat = np.random.randint(1, size=(num_segments, WIDTH, HEIGHT, 2)) return np.array(mat, dtype=np.float32) mat = [] mv_0_x = mv_origin[:, :, ::6] mv_0_y = mv_origin[:, :, 1::6] for i in range(mv_0_x.shape[2]): mv_0 = np.dstack((mv_0_x[:, :, i], mv_0_y[:, :, i])) mat.append(mv_0 + 128) # plt.imshow(mv_0) # plt.show() mat = random_sample(mat, num_segments) if is_train else fix_sample( mat, num_segments) mat = np.asarray(mat, dtype=np.float32) mv_origin = [] return mat
def load_mvs(self, num_segments, is_train): """ :param num_segments: :param is_train: :return: (counts, width//4, height//4, channels=3) 0,255 """ # mv_ref_arr=(H/4,W/4,frames*6) # mv_ref_arr is a array with 3 dimensions. The first dimension denotes Height of a frame. The second dimension denotes Width of a frame. # For every frame, it contains mv_0_x, mv_0_y, ref_0, mv_1_x, mv_1_y, ref_1. So, the third dimension denote frames*6. try: os.chdir(VIDEOS_URL) mv_origin = coviexinfo.extract(self.video_name, 'get_mv', self.num_frames, self.num_I, 0) if len(mv_origin) == 0: mat = np.random.randint(1, size=(num_segments, WIDTH, HEIGHT, 3)) return np.array(mat, dtype=np.float32) mat = [] mv_frames = mv_origin.shape[2]//6 print(mv_frames) for i in range(mv_frames): mat.append(np.dstack((mv_origin[:, :, i * 6] + 128, mv_origin[:, :, i * 6 + 1] + 128, np.zeros((WIDTH // 4, HEIGHT // 4), dtype=np.int32)))) # mat.append(mv_0) # plt.imshow(mv_0) # plt.show() mat = random_sample(mat, num_segments) if is_train else fix_sample(mat, num_segments) mat = np.asarray(mat, dtype=np.float32) return mat except Exception as e: print("When extracting MV, something wrong") traceback.print_exc()
def load_keyframes(self, num_segments, is_train): """ :param num_segments: :param is_train: :return: (counts, width, height, channels) """ os.chdir(self.data_root) frames = coviexinfo.extract(self.video_name, 'get_I', self.num_frames, self.num_I, 0) if len(frames) == 0: mat = np.random.randint(255, size=(num_segments, WIDTH, HEIGHT, 3)) return np.array(mat, dtype=np.float32) mat = [] for i in range(self.num_I): rgb = np.dstack( (frames[:, :, i * 3], frames[:, :, i * 3 + 1], frames[:, :, i * 3 + 2])) mat.append(rgb) # plt.imshow(rgb) # plt.show() mat = random_sample(mat, num_segments) if is_train else fix_sample( mat, num_segments) mat = np.asarray(mat, dtype=np.float32) return mat
def load_frames(self, video, num_segments, is_train): """ :param num_segments: :param is_train: :return: (counts, width, height, channels) """ frames = coviexinfo.extract(video, 'decode_all', 'test', 20, 0) if len(frames) == 0: mat = np.random.randint(255, size=(num_segments, WIDTH, HEIGHT, 3)) return np.array(mat, dtype=np.float32) mat = [] for i in range(frames.shape[2] // 3): rgb = np.dstack( (frames[:, :, i * 3], frames[:, :, i * 3 + 1], frames[:, :, i * 3 + 2])) mat.append(rgb) mat = random_sample(mat, num_segments) if is_train else fix_sample( mat, num_segments) mat = np.asarray(mat, dtype=np.float32) return mat