def get_frame(vid_name,frame_id): # get the oni frame openni2.initialize('/usr/lib64/') dev = openni2.Device.open_file(vid_name) print (dev.get_device_info()) # get and start the streams rgb_stream = dev.create_color_stream() depth_stream = dev.create_depth_stream() depth_stream.start() rgb_stream.start() # seek pbs = openni2.PlaybackSupport(dev) print("total frames = " + str(pbs.get_number_of_frames(depth_stream))) pbs.set_repeat_enabled(True) pbs.set_speed(0) # read the frame for i in range(0,frame_id+1): frame = depth_stream.read_frame() frame_data = frame.get_buffer_as_uint16() depth_stream.stop() # to numpy! depth = np.array(frame_data) depth = np.reshape(depth,[frame.height,frame.width]) # read the rgb for i in range(0,frame_id+1): rgb = rgb_stream.read_frame() rgb = np.array(rgb.get_buffer_as_uint8()) rgb = np.reshape(rgb,[frame.height,frame.width,3]) #code.interact(local=locals()) return depth, rgb
def get_number_of_frames(vid_name): openni2.initialize('/usr/lib64/') dev = openni2.Device.open_file(vid_name) # get and start the streams depth_stream = dev.create_depth_stream() # seek pbs = openni2.PlaybackSupport(dev) return pbs.get_number_of_frames(depth_stream)
def openDevice(video_path): try: openni2.initialize() dev = openni2.Device.open_file(video_path) pbs = openni2.PlaybackSupport(dev) pbs.set_repeat_enabled(False) pbs.set_speed(-1.0) return dev except (RuntimeError, TypeError, NameError): print(RuntimeError, TypeError, NameError)
def load_video(vid_name): depths = [] rgbs = [] # get the oni frame openni2.initialize('/usr/lib64/') dev = openni2.Device.open_file(vid_name) print (dev.get_device_info()) # get and start the streams rgb_stream = dev.create_color_stream() depth_stream = dev.create_depth_stream() depth_stream.start() rgb_stream.start() # seek pbs = openni2.PlaybackSupport(dev) n_frames = pbs.get_number_of_frames(depth_stream) print("total frames = " + str(n_frames)) pbs.set_repeat_enabled(True) pbs.set_speed(0) # read the frame for i in range(0,n_frames): print("Depth {0} of {1}".format(i,n_frames)) frame = depth_stream.read_frame() frame_data = frame.get_buffer_as_uint16() #depth_stream.stop() # to numpy! depth = np.array(frame_data) depth = np.reshape(depth,[frame.height,frame.width]) depths.append(depth) print("RGB {0} of {1}".format(i,n_frames)) rgb = rgb_stream.read_frame() rgb = np.array(rgb.get_buffer_as_uint8()) rgb = np.reshape(rgb,[frame.height,frame.width,3]) rgbs.append(rgb) #code.interact(local=locals()) return depths, rgbs
def __init__(self, filename): oni.initialize() self.filename = filename self.dev = oni.Device.open_file(filename) self.player = oni.PlaybackSupport(self.dev) self.player.set_speed(-1) self.depth_stream = self.dev.create_depth_stream() self.clr_stream = self.dev.create_color_stream() self.depth_stream.start() self.clr_stream.start() self.prep = Prepare(self) self.skeleton = None self.pause = 5 self.history = StateHistory() self.currentFrameIdx = 0 self.drag = False self.adjustment = None for x in self.history.states.keys(): self.history.states[x] = [None] * self.player.get_number_of_frames( self.depth_stream)
args = p.parse_args() model = get_conv() bit = 16 model.load_weights('weights_conv_16.h5') dev = openni2.Device try: openni2.initialize() dev = openni2.Device.open_file(args.video_path.encode('utf-8')) print(dev.get_sensor_info(openni2.SENSOR_DEPTH)) except (RuntimeError, TypeError, NameError): print(RuntimeError, TypeError, NameError) pbs = openni2.PlaybackSupport(dev) depth_stream = pbs.device.create_depth_stream() pbs.set_repeat_enabled(True) pbs.set_speed(-1.0) depth_stream.start() n_frames = pbs.get_number_of_frames(depth_stream) for i in range(0, n_frames - 1): frame_depth = depth_stream.read_frame() print("Depth {0} of {1} - {2}".format(i, n_frames, frame_depth.frameIndex)) frame_depth_data = frame_depth.get_buffer_as_uint16() depth_array = np.ndarray((frame_depth.height, frame_depth.width), dtype=np.uint16, buffer=frame_depth_data) depth_array = resize(depth_array, (img_rows, img_cols), preserve_range=True)