def save(self, clips): """ Save extracted clips to FR*.bin file. Arguments: clips: [list] a list of extracted clips of the fireball """ FRbin.writeArray(clips, self.data_dir, self.filename)
def view(dir_path, ff_path, fr_path, config, save_frames=False): """ Shows the detected fireball stored in the FR file. Arguments: dir_path: [str] Current directory. ff: [str] path to the FF bin file fr: [str] path to the FR bin file config: [conf object] configuration structure """ name = fr_path fr = FRbin.read(dir_path, fr_path) print('------------------------') print('Showing file:', fr_path) if ff_path is None: #background = np.zeros((config.height, config.width), np.uint8) # Get the maximum extent of meteor frames y_size = max([max(np.array(fr.yc[i]) + np.array(fr.size[i])//2) for i in range(fr.lines)]) x_size = max([max(np.array(fr.xc[i]) + np.array(fr.size[i])//2) for i in range(fr.lines)]) # Make the image square img_size = max(y_size, x_size) background = np.zeros((img_size, img_size), np.uint8) else: background = FFfile.read(dir_path, ff_path).maxpixel print("Number of lines:", fr.lines) first_image = True wait_time = 2*int(1000.0/config.fps) pause_flag = False for current_line in range(fr.lines): print('Frame, Y , X , size') for z in range(fr.frameNum[current_line]): # Get the center position of the detection on the current frame yc = fr.yc[current_line][z] xc = fr.xc[current_line][z] # Get the frame number t = fr.t[current_line][z] # Get the size of the window size = fr.size[current_line][z] print(" {:3d}, {:3d}, {:3d}, {:d}".format(t, yc, xc, size)) img = np.copy(background) # Paste the frames onto the big image y_img = np.arange(yc - size//2, yc + size//2) x_img = np.arange(xc - size//2, xc + size//2) Y_img, X_img = np.meshgrid(y_img, x_img) y_frame = np.arange(len(y_img)) x_frame = np.arange(len(x_img)) Y_frame, X_frame = np.meshgrid(y_frame, x_frame) img[Y_img, X_img] = fr.frames[current_line][z][Y_frame, X_frame] # Save frame to disk if save_frames: frame_file_name = fr_path.replace('.bin', '') + "_line_{:02d}_frame_{:03d}.png".format(current_line, t) cv2.imwrite(os.path.join(dir_path, frame_file_name), img) # Show the frame cv2.imshow(name, img) # If this is the first image, move it to the upper left corner if first_image: cv2.moveWindow(name, 0, 0) first_image = False if pause_flag: wait_time = 0 else: wait_time = 2*int(1000.0/config.fps) # Space key: pause display. # 1: previous file. # 2: next line. # q: Quit. key = cv2.waitKey(wait_time) & 0xFF if key == ord("1"): cv2.destroyWindow(name) return -1 elif key == ord("2"): break elif key == ord(" "): # Pause/unpause video pause_flag = not pause_flag elif key == ord("q") : os._exit(0) cv2.destroyWindow(name)