private NuiSource() { this.context = new Context("openni.xml"); // Initialise generators this.imageGenerator = this.context.FindExistingNode(NodeType.Image) as ImageGenerator; this.depthGenerator = this.context.FindExistingNode(NodeType.Depth) as DepthGenerator; this.depthGenerator.GetAlternativeViewPointCap().SetViewPoint(this.imageGenerator); this.userGenerator = new UserGenerator(this.context); this.imageMetadata = new ImageMetaData(); var imageMapMode = this.imageGenerator.GetMapOutputMode(); this.depthMetadata = new DepthMetaData(); var depthMapMode = this.depthGenerator.GetMapOutputMode(); this.depthHistogram = new int[this.depthGenerator.GetDeviceMaxDepth()]; // Initialise bitmaps this.cameraImage = new WriteableBitmap( (int)imageMapMode.nXRes, (int)imageMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null); this.depthImage = new WriteableBitmap( (int)depthMapMode.nXRes, (int)depthMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null); // Initialise user generator this.userGenerator.NewUser += this.UserGenerator_NewUser; this.userGenerator.LostUser += this.UserGenerator_LostUser; this.userGenerator.StartGenerating(); this.ShowPlayerLabels = true; // Initialise background thread var cameraThread = new Thread(this.CameraThread) { IsBackground = true }; cameraThread.Start(); }
private NuiSource() { context = new Context("openni.xml"); // Initialise generators imageGenerator = this.context.FindExistingNode(NodeType.Image) as ImageGenerator; depthGenerator = this.context.FindExistingNode(NodeType.Depth) as DepthGenerator; imageMetadata = new ImageMetaData(); var imageMapMode = imageGenerator.GetMapOutputMode(); depthMetadata = new DepthMetaData(); var depthMapMode = depthGenerator.GetMapOutputMode(); depthHistogram = new int[depthGenerator.GetDeviceMaxDepth()]; // Initialise bitmaps cameraImage = new WriteableBitmap((int)imageMapMode.nXRes, (int)imageMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null); depthImage = new WriteableBitmap((int)depthMapMode.nXRes, (int)depthMapMode.nYRes, 96, 96, PixelFormats.Rgb24, null); // Initialise background thread var cameraThread = new Thread(this.CameraThread) { IsBackground = true }; cameraThread.Start(); var userGenerator = new UserGenerator(context); userGenerator.NewUser += this.UserGenerator_NewUser; userGenerator.LostUser += this.UserGenerator_LostUser; }
private static IntPtr CreateBasedOn(ImageGenerator basedOn, string name) { IntPtr handle; UInt32 status = OpenNIImporter.xnCreateMockNodeBasedOn(basedOn.GetContext().InternalObject, basedOn.InternalObject, name, out handle); WrapperUtils.CheckStatus(status); return handle; }
private static IntPtr CreateBasedOn(ImageGenerator basedOn, string name) { IntPtr handle; UInt32 status = OpenNIImporter.xnCreateMockNodeBasedOn(basedOn.GetContext().InternalObject, basedOn.InternalObject, name, out handle); WrapperUtils.CheckStatus(status); return(handle); }
public Form1() { InitializeComponent(); this.context = new Context(SAMPLE_XML_FILE); this.image = context.FindExistingNode(NodeType.Image) as ImageGenerator; if (this.image == null) { throw new Exception("Viewer must have an image node!"); } var mapMode = this.image.GetMapOutputMode(); this.bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb); this.shouldRun = true; this.readerThread = new Thread(ReaderThread); this.readerThread.Start(); }
public void Initialize() { context = new Context(@"..\..\..\data\openniconfig.xml"); depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; rgb = context.FindExistingNode(NodeType.Image) as ImageGenerator; if (depth == null) throw new Exception(@"Error in Data\openniconfig.xml. No depth node found."); if (rgb == null) throw new Exception(@"Error in Data\openniconfig.xml. No rgb node found."); MapOutputMode mapMode = depth.GetMapOutputMode(); // Initialize member variables depthHistogram = new int[depth.GetDeviceMaxDepth()]; // initialize rgb array xn.ImageMetaData rgbMD = rgb.GetMetaData(); rgbData = new byte[rgbMD.XRes * rgbMD.YRes * 3]; rgbWidth = rgbMD.XRes; rgbHeight = rgbMD.YRes; xn.DepthMetaData depthMD = depth.GetMetaData(); depthData = new ushort[depthMD.XRes * depthMD.YRes]; oldDepthData = new ushort[depthMD.XRes * depthMD.YRes]; histogramImage = new byte[depthMD.XRes * depthMD.YRes * 3]; depthWidth = depthMD.XRes; depthHeight = depthMD.YRes; depthOffsetX = depthMD.XOffset; depthOffsetY = depthMD.YOffset; DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, 30); dispatcherTimer.Start(); }
public MockImageGenerator(ImageGenerator basedOn) : this(basedOn, null) { }
public MockImageGenerator(ImageGenerator basedOn, string name) : this(CreateBasedOn(basedOn, name), false) { }
private void InitOpenNi(AsyncStateData asyncData) { _niContext = new Context("openni.xml"); _imageNode = (ImageGenerator)_niContext.FindExistingNode(NodeType.Image); _imageMeta = new ImageMetaData(); _imageNode.GetMetaData(_imageMeta); // create the image bitmap source on asyncData.AsyncOperation.SynchronizationContext.Send( md => CreateImageBitmap(_imageMeta, out _rgbImageSource), null); // add depth node _depthNode = (DepthGenerator)_niContext.FindExistingNode(NodeType.Depth); _depthMeta = new DepthMetaData(); _depthNode.GetMetaData(_depthMeta); asyncData.AsyncOperation.SynchronizationContext.Send( state => CreateImageBitmap(_depthMeta, out _depthImageSource, PixelFormats.Pbgra32), null); // add scene node //_sceneNode = (SceneAnalyzer) _niContext.FindExistingNode(NodeType.Scene); //_sceneMeta = new SceneMetaData(); ////_sceneNode.GetMetaData(_sceneMeta); //asyncData.AsyncOperation.SynchronizationContext.Send( // state => CreateImageBitmap(_sceneMeta, out _sceneImageSource, PixelFormats.Pbgra32), // null); }
/// <summary> /// OpenNIスレッドの起動 /// /// </summary> private void StartOpenNI() { try { context = new Context(Application.StartupPath + Settings.OPENNI_CONFIG); } catch(GeneralException ge){ Console.WriteLine(ge.Message); this.Close(); return; } depthGenerator = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (this.depthGenerator == null) { throw new Exception("Viewer must have a depth node!"); } userGenerator = new UserGenerator(context); userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser); userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser); userGenerator.StartGenerating(); imageGenerator = context.FindExistingNode(NodeType.Image) as ImageGenerator; imageGenerator.StartGenerating(); poseDetectionCapability = new PoseDetectionCapability(userGenerator); poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected); skeletonCapability = new SkeletonCapability(userGenerator); skeletonCapability.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapability_CalibrationEnd); skeletonCapability.SetSkeletonProfile(SkeletonProfile.All); depthGenerator.GetAlternativeViewPointCap().SetViewPoint(imageGenerator); histogram = new int[depthGenerator.GetDeviceMaxDepth()]; // 出力モード //this.mapMode = depthGenerator.GetMapOutputMode(); this.mapMode = imageGenerator.GetMapOutputMode(); bitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/); shouldRun = true; openNiThread = new Thread(ReaderThread); openNiThread.Start(); }
private void CreateAndRun() { m_context = new Context(@"data\openNI.xml"); m_imageGenerator = new ImageGenerator(m_context); m_depthGenerator = new DepthGenerator(m_context); SessionManager sessionManager = new SessionManager(m_context, "Wave", "RaiseHand"); // update the state Dispatcher.BeginInvoke(() => { State = SessionState.Idle; }); sessionManager.SessionStart += SessionManager_SessionStart; sessionManager.SessionEnd += SessionManager_SessionEnd; PointControl pointControl = new PointControl(); pointControl.PrimaryPointCreate += PointControl_PrimaryPointCreate; pointControl.PrimaryPointDestroy += PointControl_PrimaryPointDestroy; pointControl.PrimaryPointUpdate += PointControl_PrimaryPointUpdate; SwipeDetector swipeDetector = new SwipeDetector(); swipeDetector.UseSteady = true; swipeDetector.SwipeLeft += SwipeDetector_SwipeLeft; swipeDetector.SwipeRight += SwipeDetector_SwipeRight; PointDenoiser denoiser = new PointDenoiser(); denoiser.AddListener(pointControl); denoiser.AddListener(swipeDetector); sessionManager.AddListener(denoiser); while (m_running) { m_context.WaitAndUpdateAll(); sessionManager.Update(m_context); } }
private void SetupKinect() { this.SkeletonUpdate += (u, s) => { }; this.StatusUpdate += (u, s) => { }; this.context = new Context(SAMPLE_XML_FILE); this.depth = context.FindExistingNode(NodeType.Depth) as DepthGenerator; if (this.depth == null) { throw new Exception("Viewer must have a depth node!"); } this.rawIm = context.FindExistingNode(NodeType.Image) as ImageGenerator; this.userGenerator = new UserGenerator(this.context); this.skeletonCapbility = new SkeletonCapability(this.userGenerator); this.poseDetectionCapability = new PoseDetectionCapability(this.userGenerator); this.calibPose = this.skeletonCapbility.GetCalibrationPose(); this.userGenerator.NewUser += new UserGenerator.NewUserHandler(userGenerator_NewUser); this.userGenerator.LostUser += new UserGenerator.LostUserHandler(userGenerator_LostUser); this.poseDetectionCapability.PoseDetected += new PoseDetectionCapability.PoseDetectedHandler(poseDetectionCapability_PoseDetected); this.skeletonCapbility.CalibrationEnd += new SkeletonCapability.CalibrationEndHandler(skeletonCapbility_CalibrationEnd); this.skeletonCapbility.SetSkeletonProfile(SkeletonProfile.All); this.joints = new Dictionary<uint, Dictionary<SkeletonJoint, SkeletonJointPosition>>(); this.userGenerator.StartGenerating(); this.histogram = new int[this.depth.GetDeviceMaxDepth()]; MapOutputMode mapMode = this.depth.GetMapOutputMode(); this.depthBitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes/*, System.Drawing.Imaging.PixelFormat.Format24bppRgb*/); this.rawImBitmap = new Bitmap((int)mapMode.nXRes, (int)mapMode.nYRes, System.Drawing.Imaging.PixelFormat.Format24bppRgb); this.shouldRun = true; this.readerThread = new Thread(ReaderThread); this.readerThread.Start(); }