def open_stream(self, stream_type, width=None, height=None, fps=None, pixelFormat=None): try: if (not self.has_sensor(stream_type)): logger.error("Device does not have stream type of {}".format( stream_type)) return False stream_name = STREAM_NAMES[stream_type.value] if self.stream[stream_name].active: raise (Exception( "{} stream already active!".format(stream_name))) self.stream[stream_name].start() # TODO: No feedback if stream start was successful, evaluate? video_mode = None if width is not None and height is not None and fps is not None and pixelFormat is not None: video_mode = openni2.VideoMode(pixelFormat=pixelFormat, resolutionX=width, resolutionY=height, fps=fps) self.stream[stream_name]._set_video_mode(video_mode) self.stream[stream_name].active = True except Exception as e: logger.error('Failed to open stream', exc_info=True) return False return True
def __init__(self, stream, fps, image_size, pixel_format): ImageSource.__init__(self) self.stream = stream self.stream.set_video_mode( openni2.VideoMode(pixelFormat=pixel_format, fps=fps, resolutionX=image_size[0], resolutionY=image_size[1])) self.stream.start()
import numpy as np import cv2 from YOLO_API import YOLO yolo = YOLO() model = load_model('model/LSTM_1105.h5') modelb = load_model('model/Behavior_0924.h5') # %% from openni import openni2 openni2.initialize('openNI/GIGABYTE DigitalSignage_OpenNI2_driver/Windows/OpenNI2/x64') # can also accept the path of the OpenNI redistribution dev = openni2.Device.open_any() depth_stream = dev.create_depth_stream() mode = openni2.VideoMode(pixelFormat = openni2.PIXEL_FORMAT_DEPTH_1_MM, resolutionX = 80, resolutionY = 60, fps = 30) depth_stream.set_video_mode(mode) depth_stream.start() #%% import math from pykalman import KalmanFilter import time from PIL import Image, ImageDraw, ImageFont def toWorld(frame,p): X,Y,Z = openni2.convert_depth_to_world(depth_stream,p[1],p[0],frame[p[0],p[1]]) x = np.radians(40) y = np.radians(0) z = np.radians(0)
def video_mode(self): return openni2.VideoMode(pixelFormat=self.pixelFormat, resolutionX=self.resolutionX, resolutionY=self.resolutionY, fps=self.fps)