Example #1
0
        /// <summary>
        /// Gets a nice C# library version of the Frame Mode class
        /// </summary>
        /// <param name="mode">
        /// A <see cref="FreenectFrameMode"/>
        /// </param>
        /// <returns>
        /// A <see cref="FrameMode"/>
        /// </returns>
        internal static FrameMode FromInterop(FreenectFrameMode nativeMode, FrameModeType type)
        {
            FrameMode mode = null;

            // Make sure mode is valid
            if (nativeMode.IsValid == 0)
            {
                return(null);
            }

            // Figure out what type of mode it is
            if (type == FrameMode.FrameModeType.VideoFormat)
            {
                mode = new VideoFrameMode();
            }
            else if (type == FrameMode.FrameModeType.DepthFormat)
            {
                mode = new DepthFrameMode();
            }

            // Copy over rest of data
            mode.nativeMode          = nativeMode;
            mode.Size                = nativeMode.Bytes;
            mode.Width               = nativeMode.Width;
            mode.Height              = nativeMode.Height;
            mode.Resolution          = nativeMode.Resolution;
            mode.DataBitsPerPixel    = nativeMode.DataBitsPerPixel;
            mode.PaddingBitsPerPixel = nativeMode.PaddingBitsPerPixel;
            mode.FrameRate           = nativeMode.Framerate;
            mode.videoFormat         = nativeMode.VideoFormat;
            mode.depthFormat         = nativeMode.DepthFormat;

            return(mode);
        }
        /// <summary>
        /// Sets the current depth camera mode
        /// </summary>
        /// <param name="mode">
        /// Depth camera mode to switch to.
        /// </param>
        protected void SetDepthMode(DepthFrameMode mode)
        {
            // Is this a different mode?
            if (this.Mode == mode)
            {
                return;
            }

            // Stop camera first if running
            bool running = this.IsRunning;

            if (running)
            {
                this.Stop();
            }

            // Check to make sure mode is valid by finding it again
            DepthFrameMode foundMode = DepthFrameMode.Find(mode.Format, mode.Resolution);

            if (foundMode == null)
            {
                throw new Exception("Invalid Depth Camera Mode: [" + mode.Format + ", " + mode.Resolution + "]");
            }

            // Save mode
            this.captureMode = mode;

            // All good, switch to new mode
            int result = KinectNative.freenect_set_depth_mode(this.parentDevice.devicePointer, foundMode.nativeMode);

            if (result != 0)
            {
                throw new Exception("Mode switch failed. Error Code: " + result);
            }

            // Update depth map
            this.UpdateNextFrameDepthMap();

            // If we were running before, start up again
            if (running)
            {
                this.Start();
            }
        }
        /// <summary>
        /// Updates list of depth modes that this camera has.
        /// </summary>
        private void UpdateDepthModes()
        {
            List <DepthFrameMode> modes = new List <DepthFrameMode>();

            // Get number of modes
            int numModes = KinectNative.freenect_get_depth_mode_count(this.parentDevice.devicePointer);

            // Go through modes
            for (int i = 0; i < numModes; i++)
            {
                DepthFrameMode mode = (DepthFrameMode)FrameMode.FromInterop(KinectNative.freenect_get_depth_mode(i), FrameMode.FrameModeType.DepthFormat);
                if (mode != null)
                {
                    modes.Add(mode);
                }
            }

            // All done
            this.Modes = modes.ToArray();
        }
Example #4
0
		/// <summary>
		/// Gets a nice C# library version of the Frame Mode class
		/// </summary>
		/// <param name="mode">
		/// A <see cref="FreenectFrameMode"/>
		/// </param>
		/// <returns>
		/// A <see cref="FrameMode"/>
		/// </returns>
		internal static FrameMode FromInterop(FreenectFrameMode nativeMode, FrameModeType type)
		{
			FrameMode mode = null;
			
			// Make sure mode is valid
			if(nativeMode.IsValid == 0)
			{
				return null;
			}
			
			// Figure out what type of mode it is
			if(type == FrameMode.FrameModeType.VideoFormat)
			{
				mode = new VideoFrameMode();
			}
			else if(type == FrameMode.FrameModeType.DepthFormat)
			{
				mode = new DepthFrameMode();
			}
			
			// Copy over rest of data
			mode.nativeMode = nativeMode;
			mode.Size = nativeMode.Bytes;
			mode.Width = nativeMode.Width;
			mode.Height = nativeMode.Height;
			mode.Resolution = nativeMode.Resolution;
			mode.DataBitsPerPixel = nativeMode.DataBitsPerPixel;
			mode.PaddingBitsPerPixel = nativeMode.PaddingBitsPerPixel;
			mode.FrameRate = nativeMode.Framerate;
			mode.videoFormat = nativeMode.VideoFormat;
			mode.depthFormat = nativeMode.DepthFormat;
			
			return mode;
		}
Example #5
0
		/// <summary>
		/// Sets the current depth camera mode
		/// </summary>
		/// <param name="mode">
		/// Depth camera mode to switch to.
		/// </param>
		protected void SetDepthMode(DepthFrameMode mode)
		{
			// Is this a different mode?
			if(this.Mode == mode)
			{
				return;	
			}
			
			// Stop camera first if running
			bool running = this.IsRunning;
			if(running)
			{	
				this.Stop();
			}
			
			// Check to make sure mode is valid by finding it again
			DepthFrameMode foundMode = DepthFrameMode.Find(mode.Format, mode.Resolution);
			if(foundMode == null)
			{
				throw new Exception("Invalid Depth Camera Mode: [" + mode.Format + ", " + mode.Resolution + "]");
			}
			
			// Save mode
			this.captureMode = mode;
			
			// All good, switch to new mode
			int result = KinectNative.freenect_set_depth_mode(this.parentDevice.devicePointer, foundMode.nativeMode);
			if(result != 0)
			{
				throw new Exception("Mode switch failed. Error Code: " + result);
			}
			
			// Update depth map
			this.UpdateNextFrameDepthMap();
			
			// If we were running before, start up again
			if(running)
			{
				this.Start();	
			}
		}